title: CORS with jQuery and XDomainRequest in IE8/9
body: <p><strong>UPDATE:</strong> I highly recommend not investing any time in XDomainRequest, because it is a terribly poor implementation with many limitations. It basically only really works for GET requests to non-ssl servers, so you might as well use jsonp or whatever.</p>
  
  <hr>
  
  <p>I am using CORS to call a cross domain API, however Internet Explorer is giving issues. CORS should be possible in IE8 and IE9 through the <code>XDomainRequest</code> object, however I can't get things to work..</p>
  
  <p>JQuery <a href="http://bugs.jquery.com/ticket/8283" rel="nofollow noreferrer">refuses</a> to provide native support for XDomainRequest, however several jQuery plugins are suggested to add this support. This <a href="https://stackoverflow.com/questions/10232017/ie9-jquery-ajax-with-cors-returns-access-is-denied">topic</a> suggest two such plugins: <a href="https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest/blob/master/jQuery.XDomainRequest.js" rel="nofollow noreferrer">jQuery.XDomainRequest.js</a> and <a href="https://github.com/tlianza/ajaxHooks/blob/master/src/ajax/xdr.js" rel="nofollow noreferrer">xdr.js</a>, which has been reported to work. Afaik, the plugins should automatically override behavior of <code>jQuery.ajax</code>. I found another plugin <a href="https://github.com/Ovea/cors/blob/master/src/main/resources/com/ovea/cors/jquery.ie.cors.js" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I put a little demo pages with the respective plugins <a href="http://www.stat.ucla.edu/~jeroen/cors/test1.html" rel="nofollow noreferrer">jQuery.XDomainRequest</a> and <a href="http://www.stat.ucla.edu/~jeroen/cors/test2.html" rel="nofollow noreferrer">xdr</a> and <a href="http://www.stat.ucla.edu/~jeroen/cors/test3.html" rel="nofollow noreferrer">jquery.ie.cors</a> that perform ajax requests to a CORS enabled server. The pages are working in Chrome and Firefox, however IE8/9 instantly throw a permission denied error (even before making the request). This <a href="http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/30ef3add-767c-4436-b8a9-f1ca19b4812e" rel="nofollow noreferrer">MSDN post</a> suggest adding another handler <code>xhr.onprogress = function() {};</code> but I tried this and it isn't working either.</p>
  
  <p>Any clues what I am doing wrong? I have also tested with IE8 now using MS virtual server, but it has exactly the same problem.</p>
  
  <p>Edit: OK so I figured out that part of the problem was that I was using POST over HTTPS. Apparently XDomainRequest does not allow CORS over HTTPS. I can switch to HTTP but I really need POST. </p>
  
  <p>Edit2: See <a href="https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest/issues/1" rel="nofollow noreferrer">this issue on github</a> for the end of this story. It turns out that when using HTTP POST, the xDomainRequest can only encode the request body (arguments) as <code>text/plain</code>. This pretty much makes it worthless, because everyone uses <code>application/x-www-form-urlencoded</code> or <code>multipart/form-data</code>. </p>