Last active
August 29, 2015 14:07
-
-
Save diegocasmo/00c97f7c542b1fa10feb to your computer and use it in GitHub Desktop.
Javascript CORS Ajax request IE < 9 fallback.
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
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