私は現在ローカルホストで実行しています:
$.getJSON("http://localhost/call", function(json) {
alert(json.something);
});
http://localhost/call
を返しますが{something:1}
、何も警告されません。
私は現在ローカルホストで実行しています:
$.getJSON("http://localhost/call", function(json) {
alert(json.something);
});
http://localhost/call
を返しますが{something:1}
、何も警告されません。
{something:1}
ただし、有効なJSON文字列ではありません
{"something":1}
は。
通話を次のように置き換える場合
$.ajax({
url: 'http://localhost/call',
dataType: 'json',
success: function(){},
error: function(xhr, textStatus, errorThrown){
//you should get a parse error and end up here
}
});
error
あなたはコールバックで終わるはずです。
あなたのphpファイルで:
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);