Reputation: 2292
I have a problem with processing a JSON object.
When I do echo
the result I get this:
result : undefined
$.post("./php/date_information.php", function(temp){
alert(temp.weekNumber); // HERE
$('select[name="week"]').val(temp.weekNumber);
});
but when I change my code I get this
result : {"year":"2018","weekNumber":"39","status":"200"}
$.post("./php/date_information.php", function(temp){
alert(temp); // Here
$('select[name="week"]').val(temp.weekNumber);
});
PHP script return (JSON FORMAT):
{"year":"2018","weekNumber":"39","status":"200"}
I have no idea why JQuery doesn't take temp.weekNumber
. Any ideas?
Upvotes: 1
Views: 67
Reputation: 981
Set the content type to json in your PHP script, before echoing the content
header('Content-Type: application/json');
Upvotes: 1