Created
January 16, 2012 05:57
-
-
Save mewlist/1619284 to your computer and use it in GitHub Desktop.
Cross-Origin Resource Sharing (CORS) for jQuery for IE8+
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
$.ajaxTransport("+*", function( options, originalOptions, jqXHR ) { | |
if(jQuery.browser.msie && window.XDomainRequest) { | |
var xdr; | |
return { | |
send: function( headers, completeCallback ) { | |
// Use Microsoft XDR | |
xdr = new XDomainRequest(); | |
xdr.open("get", options.url); | |
xdr.onload = function() { | |
if(this.contentType.match(/\/xml/)){ | |
var dom = new ActiveXObject("Microsoft.XMLDOM"); | |
dom.async = false; | |
dom.loadXML(this.responseText); | |
completeCallback(200, "success", [dom]); | |
}else{ | |
completeCallback(200, "success", [this.responseText]); | |
} | |
}; | |
xdr.ontimeout = function(){ | |
completeCallback(408, "error", ["The request timed out."]); | |
}; | |
xdr.onerror = function(){ | |
completeCallback(404, "error", ["The requested resource could not be found."]); | |
}; | |
xdr.send(); | |
}, | |
abort: function() { | |
if(xdr)xdr.abort(); | |
} | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment