javascript Evil Firefox 错误——“底层对象不支持参数或操作”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16677893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 05:36:17  来源:igfitidea点击:

Evil Firefox Error -- "A parameter or an operation is not supported by the underlying object"

javascriptjqueryfirefoxcors

提问by streetlight

I'm trying to figure out what is going on here. I've been at it for hours now and can't seem to get a grip on why this is happening.

我想弄清楚这里发生了什么。我已经研究了几个小时,似乎无法理解为什么会发生这种情况。

I'm making a few AJAX calls, and I keep getting this error back only in Firefox (version 21) on Mac OS X.

我进行了几次 AJAX 调用,并且仅在 Mac OS X 上的 Firefox(版本 21)中不断出现此错误。

Here is the error:

这是错误:

 "[Exception... "A parameter or an operation is not supported by the underlying object" 
   code: "15" nsresult: "0x8053000f (InvalidAccessError)"  location: 
   "https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js Line: 6"

I'm making a CORS call, so I set up my AJAX like so:

我正在拨打 CORS 电话,所以我像这样设置了我的 AJAX:

$.ajaxSetup({
        crossDomain: true,
        xhrFields: {
            withCredentials: true
        }

    });

And continue calls henceforth. Basically, does anyone out there have ANY experience with this error? I see some posts online but they all seem to do with Cross-Domain CSS, which I'm not using.

并在此后继续通话。基本上,有没有人对这个错误有任何经验?我在网上看到一些帖子,但它们似乎都与跨域 CSS 相关,我没有使用它。

回答by streetlight

Okay, so after of hours of testing (and great discussion from @Dave and @danronmoon, I've finally figured out what's going on.

好的,经过数小时的测试(以及@Dave 和@danronmoon 的精彩讨论,我终于弄清楚发生了什么。

The CORS (Cross-Domain Resource Sharing) calls I was making were set to 'async: false' -- (which I realize I did not include in my original post, as I thought it was inconsequential) this, seems to operate fine in all browsers except Firefox, where jQuery will bark at you and your ajax call will fail.

我所做的 CORS(跨域资源共享)调用被设置为“async: false”——(我意识到我没有包含在我的原始帖子中,因为我认为它无关紧要)这似乎在除 Firefox 之外的所有浏览器,其中 jQuery 会向您吠叫并且您的 ajax 调用将失败。

Thank you all for your help and I hope this helps someone else!

感谢大家的帮助,我希望这对其他人有所帮助!

回答by Bill'o

this is the real solution by Diogo Cardoso, the xhr object or parent seems to lack a toString() method

这是 Diogo Cardoso 的真正解决方案,xhr 对象或父对象似乎缺少 toString() 方法

CORS synchronous requests not working in firefox

CORS 同步请求在 Firefox 中不起作用

回答by Gio Asencio

Yes, it is a CORS problem caused by using ajax. But as user320550 asks, what if you NEED to use the property 'async:false'? I found that using the 'withCredentials:false' property as a workaround fixes the issue on firefox and doesn't affect other browsers.

是的,是使用ajax导致的CORS问题。但正如 user320550 所问,如果您需要使用属性“async:false”怎么办?我发现使用 'withCredentials:false' 属性作为解决方法可以解决 firefox 上的问题,并且不会影响其他浏览器。

回答by Xenos

Since this is the first duckduckgo result for InvalidAccessError: A parameter or an operation is not supported by the underlying objectI will add another source for this.

由于这是第一个duckduckgo结果,InvalidAccessError: A parameter or an operation is not supported by the underlying object我将为此添加另一个来源。

If you deal with such error when doing iframe/window actions, then you're probably prevented by the iframe's sandboxattribute (see https://html.spec.whatwg.org/multipage/iframe-embed-object.html#attr-iframe-sandbox) even when being on the same origin.

如果您在执行 iframe/window 操作时处理此类错误,那么您可能会被 iframe 的sandbox属性阻止(请参阅https://html.spec.whatwg.org/multipage/iframe-embed-object.html#attr-iframe -sandbox) 即使在同一来源。

In my case, an iframewas trying to do a window.top.location.href = ...after a form submission success. The allow-top-navigationsandbox option is mandatory to do so. Funny thing, this sandbox option is notmandatory to reloadthe top browsing context... it's only required for navigating in it.

就我而言,在表单提交成功后iframe尝试执行window.top.location.href = ...。在allow-top-navigation沙箱选项是强制性这样做。有趣的是,这个沙箱选项不是强制重新加载顶部浏览上下文......它只需要在其中导航。