2

总结一下:一切都与以下完美无瑕:

站点 => 通过 jQuery getJSON => S3 JSON 文件(启用 CORS)

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

这在除 IE9 之外的所有浏览器中都完美无缺。

有任何想法吗?我认为 CORS 规则可以修复 IE9,但显然不是。这是另一部分:我在 IE9 控制台中没有收到任何错误,所以我不得不逐行解决这个糟糕的 CORS 问题。

4

1 回答 1

3

IE9 使用该XDomainRequest对象进行 CORS 请求,这是XMLHttpRequest其他浏览器使用该对象的一个​​受限版本。XDomainRequest 对象的概述可以在这里找到:

http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

请特别查看第 3 项,其中指出:“不得将自定义标头添加到请求中”。通过查看您的配置,您似乎需要一个Authorization标题。这在 IE9 中是不允许的。(尽管可以肯定的是,查看一个有关您如何提出请求的示例会很有帮助)。

另请注意,如果您还没有这样做,您应该使用 IE8/9 的 XDomainRequest。本文提供了一个如何选择正确对象的示例:

http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/

相关的代码是:

function createCORSRequest(method, url){
  var xhr = new XMLHttpRequest();
  if ("withCredentials" in xhr){
    xhr.open(method, url, true);
  } else if (typeof XDomainRequest != "undefined"){
    xhr = new XDomainRequest();
    xhr.open(method, url);
  } else {
    xhr = null;
  }
  return xhr;
}
于 2013-08-03T21:16:44.537 回答