Created
March 27, 2013 06:08
-
-
Save lakenen/5252086 to your computer and use it in GitHub Desktop.
jQuery XDR for IE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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