哪些浏览器允许使用 Access-Control-Allow-Origin: * 进行跨域 ajax 调用?

发布于 2024-10-06 18:30:42 字数 167 浏览 1 评论 0原文

哪些浏览器允许使用 Access-Control-Allow-Origin: * 进行跨域 ajax 调用?我正在设置 REST 服务,并尝试确定是否需要支持 JSONP 以允许跨域 javascript 访问,或者设置 Access-Control-Allow-Origin 标头是否足够好。

Which browsers allow cross domain ajax calls with Access-Control-Allow-Origin: *? I am setting a REST service and trying to decide if I need to support JSONP to allow cross domain javascript access or if it is good enough to set the Access-Control-Allow-Origin header.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把梦留给海 2024-10-13 18:30:42

这是一个参考,表明现代浏览器中的支持是合理的(但请参阅此答案末尾的注释),假设客户端代码有意处理 IE 问题。 (IE8 和 IE9 支持 CORS,但不通过 XMLHttpRequest 实现 - 您必须使用 XDomainRequest 代替,值得注意的是 jQueryPrototype 在他们的 ajax 包装器中为你做到了这一点——我不知道其他库终于得到了正确的结果。 .) 该页面实质上表示,CORS 在桌面版本中受支持:

  • IE8+(通过 XDomainRequest)、IE10+(正确)
  • Firefox 3.6+
  • Safari 4.0+
  • Chrome 6+
  • Opera 12.1+

...以及

  • iOS Safari 3.2+
  • Android 浏览器 2.1+

你必须问自己什么您的目标市场是,以及他们是否可能仍在使用旧版本的 IE,因为 您的目标受众非常重要但总体而言,您仍然(暂时)可能想查看 JSONP 界面 — 即使在以家庭为主的美国市场,IE6+IE7 = 大约 20% 的用户。我不知道有多少网站可以忽略五分之一的市场。 :-) 如果你看看企业用户,或者亚洲、非洲或中美洲的用户,这个数字会显着上升。 上述情况在 2010 年是正确的。在 2013 年,中国确实是唯一坚持使用 IE6 的国家(那里>24%)。在全球范围内,IE6和IE7用户已转向IE8和IE9,甚至大企业和政府用户也终于“意识到”了安全风险。 IE8 将会陪伴我们一段时间(因为这与 Windows XP 上的 IE 一样高),但您可以打赌,使用 IE9 的近 20% 很快就会使用 IE10。

Here's one reference suggesting that support in modern browsers is reasonable (but see the note at the end of this answer), assuming client-side code handles the IE issue on purpose. (IE8 and IE9 support CORS, but not via XMLHttpRequest —you have to use XDomainRequest instead, and it's worth noting that neither jQuery nor Prototype does that for you in their ajax wrappers — I don't know about other libraries. IE10 finally gets it right.) That page says, in essence, that CORS is supported in the desktop versions of:

  • IE8+ (via XDomainRequest), IE10+ (properly)
  • Firefox 3.6+
  • Safari 4.0+
  • Chrome 6+
  • Opera 12.1+

...as well as

  • iOS Safari 3.2+
  • Android browser 2.1+

You have to ask yourself what your target market is and whether they're likely to still be using older versions of IE, because it matters quite a lot who you're targeting. But overall, you still (for the moment) probably want to look at a JSONP interface — even in the U.S. mostly-home market, IE6+IE7 = about 20% of the users. I don't know many sites that can just ignore a fifth of the market. :-) And if you look at corporate users, or users in Asia or Africa or Central America, that number goes up markedly. The foregoing was true in 2010. Here in 2013, China is really the only holdout using IE6 (>24% there). Worldwide, IE6 and IE7 users have moved on to IE8 and IE9, and even big corporate and government users have finally "got it" about the security risks. IE8 will be with us for a while (as that's has high as IE goes on Windows XP), but you can bet the nearly 20% using IE9 will be on IE10 soon.

终止放荡 2024-10-13 18:30:42

我在使用 Access-Control-Allow-Origin: * 时遇到了一些问题。我相信这与 cookie 和预检请求(POST)有关。因此,最好指定您要从哪个域进行这些调用。

I had some problems when using Access-Control-Allow-Origin: *. I believe it had something to do with cookies and preflight request(POST). So it is better to specify from which domain you are going to make these calls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文