相关疑难解决方法(0)

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

我有一个非常简单的测试页面,它使用jQuery的$ .getJSON和$ .ajax方法的XHR请求.同一页面在某些情况下有效,而在其他情况下则无效.特别是,它在Ubuntu上的Chrome中不起作用.

我正在使用Chrome 5.0.342.7测试版测试Ubuntu 9.10,使用Chrome 5.0.307.9测试版测试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
Run Code Online (Sandbox Code Playgroud)

如果它不起作用,Chrome控制台将显示以下内容:

index.html:16Using getJSON
index.html:21null
index.html:22Uncaught TypeError: Cannot read property 'result' of null
index.html:29Using ajax with …
Run Code Online (Sandbox Code Playgroud)

ajax jquery json google-chrome

48
推荐指数
3
解决办法
10万
查看次数

标签 统计

ajax ×1

google-chrome ×1

jquery ×1

json ×1