Json Object Properties Are Undefined
I'm getting a JSON object back from an AJAX call and logging the result like this: console.log(response); And this is the response logged in the console: {'filename':'new.jpg','or
Solution 1:
Either put:
header("Content-type: application/jason");
in the PHP, specify dataType: "json"
in the AJAX call in the JavaScript, or call JSON.parse
.
Solution 2:
You will need to parse your string to get a proper JSON object. JSON.parse(response); will provide you with a JSON object from which you can read the properties
Solution 3:
Can you try the following example in jsfiddle.
This is not the better way you can use JSON.parse(); or $.parseJSON(); (jquery version)
But if this is your problem, json being returned as a string this fix it and you can alter your code
Solution 4:
I think the ajax / php part should look like Ajax
$.ajax({
type: "POST",
url: "link.php",
dataType: "json",
success: function(result){
alert(result.orientation);
}
});
PHP
$response=array("filename" => "$newfilename", "orientation" => "$orientation");
$response=json_encode($response);
echo$response;
Make sure that use at least 5.2 php version
Post a Comment for "Json Object Properties Are Undefined"