I currently running in localhost:
$.getJSON("http://localhost/call", function(json) {
alert(json.something);
});
http://localhost/call returns {something:1}, yet nothing is alerted.
{something:1}
Isnt a valid JSON string, however
{"something":1}
is.
If you replace your call with
$.ajax({
url: 'http://localhost/call',
dataType: 'json',
success: function(){},
error: function(xhr, textStatus, errorThrown){
//you should get a parse error and end up here
}
});
you should end up in the error callback.
In your php file:
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
$arr = array('something' => 1, 'somethingelse' => 2);
echo json_encode($arr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With