Skip to content

Instantly share code, notes, and snippets.

@nicolaihald
Forked from legendar/xdomainrequest.js
Created March 26, 2014 13:33
Show Gist options
  • Save nicolaihald/9783212 to your computer and use it in GitHub Desktop.
Save nicolaihald/9783212 to your computer and use it in GitHub Desktop.
// override default jQuery transport for IE
if(window['XDomainRequest']) {
// save default xhr
jQuery.ajaxSettings.xhr_back = jQuery.ajaxSettings.xhr;
jQuery.ajaxSettings.xhr = function() {
if(this.crossDomain) {
try {
// IE sucs
var xhr = new window.XDomainRequest();
xhr.onload = function() {
setTimeout(function(a,b,c) {
xhr.readyState = 4;
xhr.status = 200;
xhr.getAllResponseHeaders = function(){return '';}
xhr.onreadystatechange.apply(this, arguments);
}, 22);
};
return xhr;
} catch(e) {}
}
// return original xhr
return jQuery.ajaxSettings.xhr_back.apply(this, arguments);
};
// also, override the support check
jQuery.support.cors = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment