我有一个非常简单的测试页面 http://issues.tauren.com/testjson/index.html它通过 jQuery 的 $.getJSON 和 $.ajax 方法使用 XHR 请求。同一页面在某些情况下有效,但在其他情况下则无效。具体来说,它在 Ubuntu 上的 Chrome 中不起作用。
我正在使用 Chrome 5.0.342.7 beta 的 Ubuntu 9.10 和使用 Chrome 5.0.307.9 beta 的 Mac OSX 10.6.2 进行测试。
- 当文件从 Ubuntu/Chrome 和 Mac/Chrome (在这里尝试一下 http://issues.tauren.com/testjson/index.html).
- 当文件安装在 Mac/Chrome 的本地硬盘上时(通过 file:///... 访问),它可以正常工作。
- It FAILS当文件安装在 Ubuntu/Chrome 中的本地硬盘上时(使用 file:///... 访问)。
可以从此处以 tar/gzip 文件形式下载这一小组 3 个文件:http://issues.tauren.com/testjson/testjson.tgz http://issues.tauren.com/testjson/testjson.tgz
当它运行时,Chrome 控制台会显示:
XHR finished loading: "http://issues.tauren.com/testjson/data.json".
index.html:16Using getJSON
index.html:21
Object
result: "success"
__proto__: Object
index.html:22success
XHR finished loading: "http://issues.tauren.com/testjson/data.json".
index.html:29Using ajax with json dataType
index.html:34
Object
result: "success"
__proto__: Object
index.html:35success
XHR finished loading: "http://issues.tauren.com/testjson/data.json".
index.html:46Using ajax with text dataType
index.html:51{"result":"success"}
index.html:52undefined
当它不起作用时,Chrome 控制台将显示以下内容:
index.html:16Using getJSON
index.html:21null
index.html:22Uncaught TypeError: Cannot read property 'result' of null
index.html:29Using ajax with json dataType
index.html:34null
index.html:35Uncaught TypeError: Cannot read property 'result' of null
index.html:46Using ajax with text dataType
index.html:51
index.html:52undefined
请注意,尽管成功处理程序已运行,但它甚至不显示 XHR 请求。我发誓这之前在 Ubuntu/Chrome 中可以正常工作,并且担心出现问题。我已经卸载并重新安装了 Chrome,但这没有帮助。
有人可以在你的 Ubuntu 系统上本地尝试一下并告诉我是否有任何问题吗?请注意,它在 Firefox 中似乎运行良好。