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); } }); 
4
  • possible duplicate of Cross domain ajax request Commented Jul 9, 2013 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. Commented Jul 9, 2013 at 14:05
  • 1
    CORS with jQuery and XDomainRequest in IE8/9 has some very helpful background and library links. Commented Jul 9, 2013 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. Commented Jul 9, 2013 at 14:15

1 Answer 1

5

Use this plugin for IE8-9 Xdomain support.

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

Sign up to request clarification or add additional context in comments.

3 Comments

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 You're probably referring to 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 Thank you for finding the link. I think they refer to the limitations mentioned here: blogs.msdn.com/b/ieinternals/archive/2010/05/13/… 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.