jQuery getJSON 在 Chrome 中使用本地文件的问题 [英] Problems with jQuery getJSON using local files in Chrome

查看:41
本文介绍了jQuery getJSON 在 Chrome 中使用本地文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 非常简单的测试页面,它使用带有 jQ​​uery 的 $.getJSON 的 XHR 请求和 $.ajax 方法.同一页面在某些情况下有效,而在其他情况下无效.具体来说,它在 Ubuntu 上的 Chrome 中不起作用.

I have a very simple test page that uses XHR requests with jQuery's $.getJSON and $.ajax methods. The same page works in some situations and not in others. Specificially, it doesn't work in Chrome on Ubuntu.

我正在使用 Chrome 5.0.342.7 beta 的 Ubuntu 9.10 和使用 Chrome 5.0.307.9 beta 的 Mac OSX 10.6.2 进行测试.

I'm testing on Ubuntu 9.10 with Chrome 5.0.342.7 beta and Mac OSX 10.6.2 with Chrome 5.0.307.9 beta.

  • 当文件安装在来自 Ubuntu/Chrome 和 Mac/Chrome 的网络服务器上时它可以正常工作 (在这里试试).
  • 当文件安装在 Mac/Chrome 的本地硬盘驱动器上时它可以正常工作(通过 file:///... 访问).
  • 在 Ubuntu/Chrome 的本地硬盘驱动器上安装文件时失败(通过 file:///... 访问).
  • It works correctly when files are installed on a web server from both Ubuntu/Chrome and Mac/Chrome (try it out here).
  • It works correctly when files are installed on local hard drive in Mac/Chrome (accessed with file:///...).
  • It FAILS when files are installed on local hard drive in Ubuntu/Chrome (access with file:///...).

可以从这里下载 tar/gzip 文件中的 3 个小文件集:http://issues.tauren.com/testjson/testjson.tgz

The small set of 3 files can be downloaded in a tar/gzip file from here: http://issues.tauren.com/testjson/testjson.tgz

当它工作时,Chrome 控制台会说:

When it works, the Chrome console will say:

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 控制台会显示:

When it doesn't work, the Chrome console will show this:

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,但这没有帮助.

Notice that it doesn't even show the XHR requests, although the success handler is run. I swear this was working previously in Ubuntu/Chrome, and am worried something got messed up. I already uninstalled and reinstalled Chrome, but that didn't help.

有人可以在您的 Ubuntu 系统上本地试用并告诉我您是否有任何问题吗?请注意,它似乎在 Firefox 中运行良好.

Can someone try it out locally on your Ubuntu system and tell me if you have any troubles? Note that it seems to be working fine in Firefox.

推荐答案

这是 Chrome 的一个已知问题.

This is a known issue with Chrome.

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

Here's the link in the bug tracker:

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

这篇关于jQuery getJSON 在 Chrome 中使用本地文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆