本文介绍了有没有一个jQuery解决方案使用CORS可用时,回退到XDomainRequest在MSIE和JSONP在浏览器与niether?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愚蠢地相信所有现代浏览器都支持。

I was silly enough to believe that all modern browsers supported CORS (Cross-Origin Resource Sharing).

当我的玩具JavaScript工具在IE9或Opera上没有工作时,我发现前者只支持 CORS 通过 XDomainRequest ,jQuery似乎不支持。 Opera现在不支持 CORS

When my toy JavaScript tool didn't work on IE9 or Opera I found out that the former only supported CORS through XDomainRequest, which jQuery doesn't seem to support. Opera doesn't support CORS at all yet.

现在jQuery有一个抽象的接口,查询, CORS 查询以及 JSONP 查询的方式相同。

Now jQuery has an abstract interface that does normal same domain AJAX queries, CORS queries, and even JSONP queries the same way.

这个接口有扩展,进一步使它工作,即使使用 XDomainRequest 并回到 JSONP CORS 不可用?

Is there an extension to this interface that goes further making it work even with XDomainRequest and falling back to JSONP when CORS isn't available?

推荐答案

对于JQuery中的XDomainRequest支持:

Here is a plugin for XDomainRequest support in JQuery:

还有一个jQuery功能请求添加此功能:

There is also a jQuery feature request to add this feature:

请注意,错误报告说IE9插件可能有问题,因此YMMV。它最终被关闭,原因是插件存在来做这项工作。

Note that the bug report says that there may be an issue with the plugin in IE9, so YMMV. It ended up getting closed with the reason given that the plugin exists to do the job.

这篇关于有没有一个jQuery解决方案使用CORS可用时,回退到XDomainRequest在MSIE和JSONP在浏览器与niether?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 12:52