Bab*_*ker 3 javascript jquery json
我目前在localhost中运行:
$.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);
| 归档时间: | 
 | 
| 查看次数: | 49 次 | 
| 最近记录: |