jQuery的使用本地文件的.getJSON在Firefox 3.6.13上停止工作 [英] jQuery's .getJSON using local files stopped working on Firefox 3.6.13

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

问题描述

突然,使用jQuery的.getJSON进行本地文件访问对我来说不适用于Firefox(3.6.13)-

Suddenly, local file access using jQuery's .getJSON is not working for me on Firefox (3.6.13) - only.

我知道使它在Chrome中工作的问题-

I am aware of the problem in getting this to work in Chrome - Problems with jQuery getJSON using local files in Chrome. Using the option --allow-file-access-from-files fixes that. I now have code that works on IE, Chrome (as above) and used to work on Firefox, until now.

为您提供一些背景信息:

To give you some context:

   // get the only json file 
   var script = _.detect($('script').toArray().reverse(), function(script) {
      return script.type === 'application/json';
    });
    // script.src is now '../../json/foo/foo1.json'
    return $.getJSON(script.src, function(json) {
      alert('hello');// says 'hello' in IE, Chrome (with arg), used to work in Firefox
    });

具体来说,如小代码片段所示,.getJSON调用无法返回并说"hello"-所涉及的json文件位于本地文件系统上(例如file:///d/foo/bla.json ). JSON通过JSONLint验证程序.

Specifically, as the small code snippet shows, the .getJSON call fails to return and say 'hello' - the json file in question is on the local file system (eg file:///d/foo/bla.json). The JSON passes JSONLint validator.

我尝试禁用所有插件-我也有一个带有Ubuntu&安装在其上的Firefox(3.6.13)的安装具有相同的问题-前几天有效,现在没有.据我所知,自上次工作以来,我的代码没有任何改变.我只知道有人会因为忘了一些愚蠢的东西而给我打耳光.

I've tried disabling all addons - I also have a VM with Ubuntu & the installation of Firefox installed on it (3.6.13) has the same issue - worked a few days ago, now doesn't. Nothing in my code has changed since it was last working, to my knowledge. I just know someone is going to slap me for forgetting something really dumb.

Firefox没有显示任何错误.这在Chrome和IE上有效,可以排除最明显的错误.

Firefox shows no errors. That this works on Chrome and IE rules out most obvious mistakes.

任何有关为什么突然停止在Firefox上运行的提示或技巧,将不胜感激.

Any hints or tips as to why this might suddenly stop working on Firefox, would be greatly appreciated.

推荐答案

我认为这是由于Firefox中的一项新安全功能所致:您只能向页面目录中或子目录中的文件发出本地请求页面目录.

I think this is due to a new security feature in Firefox: You can make local requests only to files that are in the page's directory, or in the sub-directory of the page.

来自此处(重点是我):

在Gecko 1.8或更早版本中,任何两个文件:URI被认为是同源的.换句话说,本地磁盘上的任何HTML文件都可以读取本地磁盘上的任何其他文件.

In Gecko 1.8 or earlier, any two file: URIs are considered to be same-origin. In other words, any HTML file on your local disk can read any other file on your local disk.

从Gecko 1.9开始,文件只能读取某些其他文件.具体来说,仅当原始文件的父目录是目标文件的祖先目录时,文件才能读取另一个文件.但是,无法以这种方式加载目录.

Starting in Gecko 1.9, files are allowed to read only certain other files. Specifically, a file can read another file only if the parent directory of the originating file is an ancestor directory of the target file. Directories cannot be loaded this way, however.

例如,如果您具有访问另一个文件bar.html的foo.html文件,则仅当bar.html与foo.html位于同一目录中或包含在同一目录中的目录中时,加载才会成功目录为foo.html.

For example, if you have a file foo.html which accesses another file, bar.html, the load will succeed only if bar.html is either in the same directory as foo.html or in a directory contained within the same directory as foo.html.


PandaWood的脚注:我可以确认将Firefox的 about:config-> security.fileuri.strict_origin_policy 设置为false,正如您提供的链接所示,这是立即解决方案


Footnote from PandaWood: I can confirm setting Firefox's about:config -> security.fileuri.strict_origin_policy to false, as the link you provide shows, is an immediate fix

这篇关于jQuery的使用本地文件的.getJSON在Firefox 3.6.13上停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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