How to get the value from an array in ionic? - php

I have created a php file.
Response from php-
response:"{"status":true,"originalName":"1527931554722.png","generatedName":"ceabe4c3b0074eb3d64cca21493be324.png"}"
I want to get the value of generatedName in ionic.
I used this code:->
let name = response[3]; console.log(name);
It gives output 't' on console.

response:"{"status":true,"originalName":"1527931554722.png","generatedName":"ceabe4c3b0074eb3d64cca21493be324.png"}"
try response.generatedName

You do not need index here, just access the property since its already an object.
DEMO
let response = {"status":true,"originalName":"1527931554722.png","generatedName":"ceabe4c3b0074eb3d64cca21493be324.png"};
console.log(response.generatedName);

Related

JSON decode on Bit2Check.com API response

I'm using the Bit2Check.com API. I want to check emails registered on PayPal. But after supplying email address to the API, I get this response:
{"Paypal":"Linked"}
I just want to grab the "Linked" part.
You are providing me with no code, so I will have to try to answer your question in general.
You probably have
{"Paypal" : "Linked"}
stored within some variable. To access the "Linked" part, you need to json_decode() it. Code retrieving just the "Linked" string would like something like this.
$yourVariable = '{"Paypal" : "Linked"}';
$decoded = json_decode($yourVariable);
// Access only linked part
$onlyLinked = $decoded->Paypal;
// Or maybe you are interested in boolean value?
$isLinked = ($decoded->Paypal == "Linked") ? true : false;
To read more about json_decode(), visit this article on php.net.

Outputting cookie in Laravel-5/Blade

I have cookie date stored in a serialized array which I would like to access via the Blade template.
If a cookie value is set matching the current field name, then I want to show it. I am currently using the following code, but I'm not sure how to access the array value.
{{{ Cookie::has('myBookingDetails') ? Cookie::get('myBookingDetails') : old('name') }}}
The value of the myBookingDetails cookie looks like this:
a:4:{s:4:"name";s:13:"Joe Bloggs";s:5:"email";s:29:"joe#domain.co.uk";s:5:"phone";s:11:"0777777777";s:3:"reg";s:6:"123456";}
How can I access the "name" value via Blade?
The data is serialized. You need to use unserialize() function to get the data.
$data = unserialize(Cookie::get('myBookingDetails'));
$name = $data['name']
Check for existence before use.
Don't know if previous answer solved your enigma, but I could give some help.
I fought with a similar case. Seems that in template - in laravel 5.1 - I couldn't access directly to cookies:
Cookie::get('cookiename') simply returns null
cookie('cookiename') returns a Symfony\Component\HttpFoundation\Cookie, but $cookie->getValue() returns (again) null.
The good old $_COOKIE['cookiename'] returns the right cookie, so you could simply go with unserialize( $_COOKIE['myBookingDetails'] )['name']; !
PS: It should be better to handle with cookies in controller and pass a normal variable to the view!

Php - Post variable values' part at specific index is missing

I'm making a POST request to my application with a long stringified JSON like below:
/////POST PARAMETER VALUE
{"objects":[{"type":"path","originX":"center","originY":"center","left":118.63,"top":252.5,"width":41,"height":139,"fill":null,"overlayFill":null,"stroke":{"source":"function anonymous() {var patternCanvas = fabric.document.createElement('canvas');patternCanvas.width = patternCanvas.height = 10;var ctx = patternCanvas.getContext('2d');ctx.stroke`Style = quotesquare005E7Aquote;ctx.lineWidth` = 5;ctx.beginPath();ctx.moveTo(5, 0);ctx.lineTo(5, 10);ctx.closePath();ctx.stroke(); return patternCanvas;}","repeat":"repeat","offsetX":0,"offsetY":0},"strokeWidth":15,"strokeDashArray":null,"strokeLineCap":"round","strokeLineJoin":"round","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"selectable":true,"hasControls":true,"hasBorders":true,"hasRotatingPoint":true,"transparentCorners":true,"perPixelTargetFind":false,"shadow":null,"visible":true,"clipTo":null,"path":[["M",40.5,0],["Q",40.5,0,41,0],["Q",41.5,0,41.25,2],["Q",41,4,38,16.5],["Q",35,29,29.5,42],["Q",24,55,21,65],["Q",18,75,15.5,83.5],["Q",13,92,9.5,101.5],["Q",6,111,4.5,118],["Q",3,125,2,128],["Q",1,131,0.5,134],["Q",0,137,0,138],["L",0,139]],"pathOffset":{"x":0,"y":0}}],"background":""}
////// END
Every time i do this request, value comes missing. In the server the part that i highlighted is lost. I realised that it's a specific index range at the string. When i give another data in this json stringified format, it looses again the part in that index range. And i'm sure that i'm sending the value complete because i checked it at the request headers.
The problem is not about my code because i tested it with POSTMAN app and the result is same.
Anyone can help about this misterious situation. Is there anything in this value which causes some escaping. And i'm using Codeigniter.
Thanks

unable to pass the imageid to the other page using get method

This might be a simple question but now i started working on GET method so I'm kinda new to it.
I have some images which are given some unique ids:
<imagetag>;
$b is the variable that stores the ID of the image.
Now I want to pass the $b variable value to imageid.php.
The link successfully opened imageid.php in my browser but the URL looks like imageid?id=. It does not display the id in the URL.
I also tried doing this:
echo $_GET['id']; // in my imageid.php
... but it's not printing the id that I just passed to imageid.php using the GET method? Why?
There isn't really enough information in your question to give a full answer, but have you checked that $b is really holding the image ID? Also, are you side "echo $var = $_GET['id'];" wouldn't just echo whether or not $var was assigned to? (i.e. false or true).
Please provide the full code so I can reply with a better answer.

Reading JSON arrays with jQuery/JS

Alright, this pretty much goes along with my previous question. I'm still trying to figure out how to display data from an array which is created by a PHP file- using JS/jQuery. I'm working on a points system for ZetaBoards, and I've currently got it set up here. (Points will be displayed below the users post count once I get this working.. you guys can't see the +/- functions which work fine, haha. :p )
http://outlinetokens.hostei.com/scripts/output.php
So, for each user- I can get their user ID, I just don't know how to check if their name is in the array. (and if it is, display their points) I'm guessing I'll have to do something like this? Here's the chunk of the code that deals with this.. you'll see where I need help.
if (location.href.match('/topic/')) {
$.getScript('http://outlinetokens.hostei.com/scripts/output.php', function () {
$('td.c_username a.member').each(function () {
value = 0;
u = $(this).attr('href').split('profile/')[1].split('/')[0];
// this is where I need to do the 'search.' Just a basic guess.. help. D:
if (values.uid == u) {
value = values.points;
}
$(this).parents('tr').next().find('dl.user_info').append('<dt>' + options.system_name + ':</dt><dd class="Points"><span id="point_total">' + value + '</span></dd>');
});
})
}
...in case the code tag screwed it up:
http://ryjoe.pastebin.com/raw.php?i=0bsZNnVq`
Thanks! (:
Why are these lines in your data formatted like this:
{'uid','342230','name','Joe','points','250'}
instead of this:
{'uid': '342230', 'name': 'Joe', 'points','250'}
If that was formatted correctly you could access the properties.
I'm not sure if I'm reading your question right, but you can load JSON with jQuery, instead of a script.
If then, the array is one of usernames, you can just use response.hasOwnProperty(username) or similar to check if it's in the JSON object you got back
Also, in php use json_encode
You want JQuery.parseJSON. Load the data string, parse it, and assuming its valid JSON, it will become a JS object. Then just access the members in the usual way.

Categories