twalters
twalters

Reputation: 1234

jQuery .ajax getting Access Denied on Cross Domain Request in IE8/9

I am using jQuery's .ajax to pull in content from other pages into a modal window. The majority of these pages are on the same domain and work correctly across all browsers.

There is one link that goes to another domain. That link works correctly in Chrome, Firefox, and Safari but gives an Access Denied error in Internet Explorer 8 and 9.

I searched quite a bit for a solution and tried several things that have not helped so far including:

I am probably forgetting something that I tried today but that should be most of it.

Here is the code I have at the moment:

jQuery.support.cors = true;

      var request = $.ajax(
      {
        crossDomain: true,
        type: "GET",
        url: url,
        success: function () {
          console.log('success');
        },
        error: function (a, status, error) {
          console.log('error: ' + error);
        },
        complete: function () {
          console.log('complete');
        }
      });

Chrome, Firefox, and Safari log 'success' and 'complete' in the console. IE8/9 log 'error: Error: Access is denied.' and 'complete' in the console.

Upvotes: 1

Views: 15704

Answers (2)

1derboy1
1derboy1

Reputation: 11

I used this to make internet explorer work for me on cross domain ajax calls. I'd be happy to list my solution here as well, but I think that the link below probably explains in detail enough from a more intelligent user than me.

Jquery $.ajax fails in IE on cross domain calls

Upvotes: 0

ConfusedCoder
ConfusedCoder

Reputation: 103

I ran into similar problem the other day. This is what I tried and it worked like a charm

I had the attribute dataType set to jsonp (i.e. dataType: 'jsonp') this will work for GET but not for POST

If the above still doesn't work then you can reference below script from MoonScript and it hooks the support up automatically

https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest

Upvotes: 1

Related Questions