有没有一个jQuery解决方案使用CORS可用时,回退到XDomainRequest在MSIE和JSONP在浏览器与niether? [英] Is there a jQuery solution that uses CORS when available and falls back to XDomainRequest on MSIE and JSONP on browsers with niether?
问题描述
我愚蠢地相信所有现代浏览器都支持 CORS
(跨源资源共享)。
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:
https://github.com/jaubourg/ajaxHooks/blob/master/src/xdr.js
还有一个jQuery功能请求添加此功能:
There is also a jQuery feature request to add this feature:
http:// bugs.jquery.com/ticket/8283
请注意,错误报告说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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!