小编典典

使用Chrome中的本地文件的jQuery getJSON问题

ajax

我有一个非常简单的测试页面,该页面使用XHR请求和jQuery的$
.getJSON和$ .ajax方法。同一页面在某些情况下有效,而在其他情况下则无效。具体来说,它不适用于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安装在Web服务器上时,它可以正常工作(在此处尝试)。
  • 当文件安装在Mac / Chrome的本地硬盘驱动器上(通过file:/// …访问)时,它可以正常工作。
  • 失败 当文件在Ubuntu / Chrome的本地硬盘上安装(与文件访问:/// …)。

可以从以下位置以tar /
gzip文件的形式下载这3个文件的小集合: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中似乎运行良好。


阅读 387

收藏
2020-07-26

共1个答案

小编典典

这是Chrome的已知问题。

这是错误跟踪器中的链接:

问题40787:Ajax无法加载本地文件

2020-07-26