总结一下:一切都在以下方面完美运行:
站点 => 通过 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 问题。
最佳答案
IE9 使用 XDomainRequest
对象发出 CORS 请求,这是其他浏览器使用的 XMLHttpRequest
对象的有限版本。可以在此处找到 XDomainRequest 对象的概述:
特别查看第 3 项,其中指出:“不得将自定义 header 添加到请求中”。通过查看您的配置,您似乎需要一个 Authorization
header 。 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;
}
关于jquery - IE9 + CORS + jQuery + 亚马逊 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18029437/