IE11不启动CORS请求 [英] IE11 not initiating CORS request

查看:2542
本文介绍了IE11不启动CORS请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过fiddling似乎IE11不作出ajax请求,如果它是交叉起源。 FF和Chrome将至少做出请求,并且如果资源API未发送必要的标头,则会抛出错误。在我的案例中,资源API(Web API 2.0)是添加必需的标题,这将有助于IE如何提出请求,但不会。



客户的JavaScript:

  jQuery.support.cors = true; 

$ .fn.somePlugin = function(){
$ .ajax({
url:apiUrl +'/ articles / list /',
type: GET',
crossDomain:true
})。done(
function(data,textStatus,xhr){
console.log('hello world!');
});
return this;
}

ajax请求在Chrome和FF,但不是在IE11。 / p>

我试过:


  1. 添加对 XDomainRequest.js 没有任何影响。 / li>
  2. 在IE安全选项中启用跨源请求 - 即使在每个客户端计算机上执行此操作似乎很奇怪。无论如何,它没有任何区别。


解决方案

我无法使用XMLHttpRequest(),$ .ajax()或$ .ajax快捷方式检索任何CORS数据。问题原来是localhost(IIS WinPro7)。每个AJAX CORS请求均已预检,生成了


来源 http :// localhost 在Access-Control-Allow-Origin标头中找不到


错误,


XMLHttpRequest:网络错误0x80070005,访问被拒绝


当我将HTML页面移动到网络服务器时,它工作正常。


By fiddling it seems IE11 does not make an ajax request if it is cross origin. FF and Chrome will at least make the request and throw an error if the resource API is not sending necessary headers. The resource API (Web API 2.0) in my case is adding required headers which will be helpful IF IE makes the request, but it doesn't.

Client's JavaScript:

jQuery.support.cors = true;

$.fn.somePlugin = function () {
    $.ajax({
        url: apiUrl + '/articles/list/',
        type: 'GET',
        crossDomain: true
    }).done(
        function (data, textStatus, xhr) {
            console.log('hello world!');
        });
    return this;
}

The ajax request above works perfectly in Chrome and FF but not in IE11.

I've tried:

  1. adding a reference to XDomainRequest.js without any effect.
  2. enabling cross origin request in IE Security options - even though it seems bizarre to do this on every client machine. Regardless, it made no difference.

解决方案

I was having the same problem. I was unable to retrieve any CORS data using XMLHttpRequest(), $.ajax() or $.ajax shortcuts. The problem turned out to be localhost (IIS WinPro7). Every AJAX CORS request was preflighted which generated an

Origin http://localhost not found in Access-Control-Allow-Origin header

error, followed by

XMLHttpRequest: Network Error 0x80070005, Access is denied

When I moved the HTML page to a webserver it worked fine.

这篇关于IE11不启动CORS请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆