Skip to content

Instantly share code, notes, and snippets.

@legendar
Created April 13, 2012 14:47
Show Gist options
  • Save legendar/2377392 to your computer and use it in GitHub Desktop.
Save legendar/2377392 to your computer and use it in GitHub Desktop.
Cross-domain XHR IE+Jquery
// 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