Skip to content

Instantly share code, notes, and snippets.

@diegocasmo
Last active August 29, 2015 14:07
Show Gist options
  • Save diegocasmo/00c97f7c542b1fa10feb to your computer and use it in GitHub Desktop.
Save diegocasmo/00c97f7c542b1fa10feb to your computer and use it in GitHub Desktop.
Javascript CORS Ajax request IE < 9 fallback.
myAjaxFunction: function(attributes, callback) {
if ($.browser.msie && window.XDomainRequest && parseInt($.browser.version) <= 9) {
var xdr = new XDomainRequest();
xdr.open('POST', 'URL', true);
xdr.send(attributes);
xdr.onload = function() {
callback(JSON.parse(xdr.responseText));
}
} else {
$.ajax({
type: 'POST',
url: 'URL',
dataType: 'json',
crossDomain: true,
data: attributes
}).done(function( data ) {
callback(data);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment