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

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

问题描述

我有href="http://issues.tauren.com/testjson/index.html">非常简单的测试页面使用与jQuery的$ .getJSON XHR请求和$就方法

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.

我测试在Ubuntu 9.10与镀铬5.0.342.7 Beta版和Mac OSX 10.6.2 Chrome浏览器5.0.307.9 Beta版。

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.

  • 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:///...).

小套3个文件可以下载从这里一个tar / gzip文件: <一href="http://issues.tauren.com/testjson/testjson.tgz">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请求,虽然成功处理程序运行。我发誓这是工作previously在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.

下面是在bug跟踪系统的链接:

Here's the link in the bug tracker:

<一个href="http://$c$c.google.com/p/chromium/issues/detail?id=40787&q=ajax%20local&colspec=ID%20Stars%20Pri%20Area%20Feature%20Type%20Status%20Summary%20Modified%20Owner%20Mstone%20OS">Issue 40787:本地文件不与阿贾克斯加载

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

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