当PHP生成JSON时,jQuery不会将JSON对象返回给Firebug
test.json的内容包括:当PHP生成JSON时,jQuery不会将JSON对象返回给Firebug,php,jquery,json,firebug,Php,Jquery,Json,Firebug,test.json的内容包括: {"foo": "The quick brown fox jumps over the lazy dog.","bar": "ABCDEFG","baz": [52, 97]} 当我使用以下jQuery.ajax()调用来处理test.JSON中的静态JSON时 $.ajax({ url: 'test.json', dataType: 'json', data: '', success: function(data) {
{"foo": "The quick brown fox jumps over the lazy dog.","bar": "ABCDEFG","baz": [52, 97]}
当我使用以下jQuery.ajax()调用来处理test.JSON中的静态JSON时
$.ajax({
url: 'test.json',
dataType: 'json',
data: '',
success: function(data) {
$('.result').html('<p>' + data.foo + '</p>' + '<p>' + data.baz[1] + '</p>');
}
});
我在浏览器中获得了正确的输出,但Firebug只显示HTML。在Firebug中展开GET请求时,不存在JSON选项卡。试试看
<?php
header('Content-type: application/json');
$arrCoords = array('foo'=>'The quick brown fox jumps over the lazy dog.','bar'=>'ABCDEFG','baz'=>array(52,97));
echo json_encode($arrCoords);
?>
试试看
您最有可能需要设置内容类型标题:
// this is the "offical" content-type
header('Content-Type: application/json');
// or - this will probably work too
header('Content-Type: text/javascript');
您最有可能需要设置内容类型标题:
// this is the "offical" content-type
header('Content-Type: application/json');
// or - this will probably work too
header('Content-Type: text/javascript');
查看响应选项卡上的响应选项卡
// this is the "offical" content-type
header('Content-Type: application/json');
// or - this will probably work too
header('Content-Type: text/javascript');