JQuerygetJSON does not alert json
1 answer
{something:1}
Not valid JSON , however
{"something":1}
there 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 have to enter the callback error
.
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);
+8
source to share