我正在为IE8和IE9设置一个备份,为此我使用JQuery发送跨域GET请求。我在IE8和9的仿真模式下使用IE11进行测试。
服务器已为CORS正确设置,并已使用普通JavaScript XMLHttpRequest测试跨域请求。
IE8/9上下文中的请求代码如下:
$.ajax({
type:"GET",
url: url,
beforeSend : function(xhr) {
xhr.setRequestHeader('Api-Version', config.apiVersion);
xhr.setRequestHeader('Api-Account-Key', config.accountKey);
xhr.setRequestHeader('Api-Authorisation-Key', config.authorisationKey);
},
success: function(data) {
callback(data);
}
});
当发送跨域请求时(此时站点在非本地主机域下运行),显然没有发送自定义标头,这不是选项请求(来自Fiddler调试器的输出)。
GET http://localhost:35000/api/example-url HTTP/1.1
Accept: */*
Origin: http://dev.local
Accept-Language: en-GB
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: localhost:35000
DNT: 1
Connection: Keep-Alive
Pragma: no-cache
如果我使用相同的代码从同一个域发送请求,则会像我预期的那样设置标头。
GET http://localhost:35000/api/example-url HTTP/1.1
x-requested-with: XMLHttpRequest
Accept-Language: en-gb
Referer: http://localhost:35000/Documentation
access-control-request-headers: x-requested-with
api-account-key: xxxxxx
Accept: */*
api-version: 1.0
api-authorisation-key: xxxx
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: localhost:35000
DNT: 1
那么,是什么阻止了JQuery,或者可能是浏览器在跨域上下文中发送标头?
发布于 2015-11-19 16:09:52
Internet 8和9使用Internet执行跨域请求.据链接到具有CORS返回“访问被拒绝”的IE9 jQuery AJAX的此jQuery特性请求称,jQuery开发团队坚决拒绝支持XDomainRequest
,因为与XMLHttpRequest
相比,它有太多的缺点和不一致之处。
这个答案还链接到一个在jQuery中。请注意,它仍将受制于XDR
的内置限制,因此即使您可以使用插件来使jQuery使用XDR
API,它也可能解决不了您的问题。
https://stackoverflow.com/questions/26781535
复制相似问题