Skip to content

Instantly share code, notes, and snippets.

@lakenen
Created March 27, 2013 06:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lakenen/5252086 to your computer and use it in GitHub Desktop.
Save lakenen/5252086 to your computer and use it in GitHub Desktop.
jQuery XDR for IE
(function ($) {
"use strict";
if (window.XDomainRequest) {
$.ajaxTransport(function(s) {
if (s.crossDomain && s.async) {
if (s.timeout) {
s.xdrTimeout = s.timeout;
delete s.timeout;
}
var xdr;
return {
send: function(_, complete) {
function callback(status, statusText, responses, responseHeaders) {
xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
xdr = undefined;
complete(status, statusText, responses, responseHeaders);
}
xdr = new XDomainRequest();
xdr.onload = function() {
callback(200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType);
};
xdr.onerror = function() {
callback(404, "Not Found");
};
xdr.onprogress = function () {};
xdr.ontimeout = function() {
callback(0, "timeout");
};
xdr.timeout = s.xdrTimeout || Number.MAX_VALUE;
xdr.open(s.type, s.url);
xdr.send((s.hasContent && s.data) || null);
},
abort: function() {
if (xdr) {
xdr.onerror = $.noop;
xdr.abort();
}
}
};
}
});
}
})(jQuery);
@romanlevin
Copy link

Wonderful work.
However, I had issues with in in IE9 when it's in IE8 compatibility mode (even though it works fine in IE8 itself).
This worked for me in the end: https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest/blob/master/jQuery.XDomainRequest.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment