IE11 not initiating CORS request

2019-07-15 10:31发布

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.

1条回答
地球回转人心会变
2楼-- · 2019-07-15 11:21

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.

查看更多
登录 后发表回答