我正在使用jQuery的ajax方法获取静态JSON文件。数据是从本地文件系统加载的,因此没有服务器,所以我无法更改MIME类型。
在Safari中可以正常工作,但Firefox(3.6.3)报告该文件为“格式不正确”。我已经意识到并查看了Stack Overflow上的一个类似帖子: "not well-formed" error in Firefox when loading JSON file with XMLHttpRequest 我相信我的JSON格式正确:
如果我用一个文档标签包装JSON:
在Safari中可以正常工作,但Firefox(3.6.3)报告该文件为“格式不正确”。我已经意识到并查看了Stack Overflow上的一个类似帖子: "not well-formed" error in Firefox when loading JSON file with XMLHttpRequest 我相信我的JSON格式正确:
{
"_": ["appl", "goog", "yhoo", "vz", "t"]
}
我的ajax调用很简单:
$.ajax({
url: 'data/tickers.json',
dataType: 'json',
async: true,
data: null,
success: function(data, textStatus, request) {
callback(data);
}
});
如果我用一个文档标签包装JSON:
<document>JSON data</document>
如上引用的其他 Stack Overflow 问题中提到的,Ajax 调用会因解析错误而失败。
那么:在读取客户端 JSON 文件时,有没有避免 Firefox 警告的方法?