1

How to correct rewrite the Ajax request to make it work in IE 8 +, using XDomainRequest?

$.ajax({
    type: "GET",
    url: url,
    success: function(xml) {
        $('.post-msg').append(processXml(xml, config));
    },
    error: function(jqXhr, textStatus, errorThrown) {
        var errorMsg = "Request on url: " + url + " failed: " + textStatus + " error:" + errorThrown;
        alert(errorMsg);
    }
});
Geray Suinov
  • 3,521
  • 3
  • 16
  • 19
  • possible duplicate of [Cross domain ajax request](http://stackoverflow.com/questions/15477527/cross-domain-ajax-request) – Andrew Lewis Jul 09 '13 at 14:05
  • Does the site support JSONP? I know jQuery does not support cors for IE 8 and 9 because the xmlhttprequest of these browsers do not support it and because all the quirks that come with the special object that IE 8 (and I think IE 9) have with CORS the jQuery team have descided not to create that other object. So if the site has JSONP then use that if it has CORS then write your own xhr request but will still be buggy in IE 8 or 9. – HMR Jul 09 '13 at 14:05
  • 1
    [CORS with jQuery and XDomainRequest in IE8/9](http://stackoverflow.com/questions/11487216/cors-with-jquery-and-xdomainrequest-in-ie8-9) has some very helpful background and library links. – apsillers Jul 09 '13 at 14:10
  • @apsillers That concludes that CORS isn't worth considering when you want to support IE 8 and 9. The same conclusion the jQuery team came to and the reason why they don't use xDomainRequest. – HMR Jul 09 '13 at 14:15

1 Answers1

5

Use this plugin for IE8-9 Xdomain support.

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

Mihail
  • 1,469
  • 11
  • 13
  • The reason why jQuery does not support CORS in IE 8 and 9 (they could create xDomainRequest instead of XMLHttpRequest) is because support for cors in IE 8 and 9 is very poor and unpredictable. I can't find the exact link in the bug list of jQuery at the moment but some good reasons are given there not to consider CORS when you want to support IE 8 and 9. – HMR Jul 09 '13 at 14:18
  • 1
    @HMR You're probably referring to http://bugs.jquery.com/ticket/8283, which was closed as "`enhancement: plugin`", which I assume means "we're not going to support this mess; use a plugin if you must." – apsillers Jul 09 '13 at 14:26
  • @apsillers Thank you for finding the link. I think they refer to the limitations mentioned here: http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx with the note that many xhr requests would fail when trying CORS while expecting it not to fail. If you can live with these limitations and possibly other unexpected results then CORS would be an option but a warning is needed that many other programmers were not successful and had to resort to JSONP anyway is needed. – HMR Jul 09 '13 at 15:09