【发布时间】:2010-05-28 05:46:49
【问题描述】:
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) {
$('.result').html('<p>' + data.foo + '</p>' + '<p>' + data.baz[1] + '</p>');
}
});
我得到一个可以在 Firebug 中浏览的 JSON 对象。
但是,当使用相同的 ajax 调用时,URL 指向这个 php 脚本:
<?php
$arrCoords = array('foo'=>'The quick brown fox jumps over the lazy dog.','bar'=>'ABCDEFG','baz'=>array(52,97));
echo json_encode($arrCoords);
?>
打印这个相同的 JSON 对象:
{"foo":"The quick brown fox jumps over the lazy dog.","bar":"ABCDEFG","baz":[52,97]}
我在浏览器中得到了正确的输出,但 Firebug 只显示 HTML。在 Firebug 中展开 GET 请求时没有 JSON 选项卡。
【问题讨论】:
-
查看响应标签