Skip to content

Instantly share code, notes, and snippets.

@olimortimer
Created April 4, 2012 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olimortimer/2300792 to your computer and use it in GitHub Desktop.
Save olimortimer/2300792 to your computer and use it in GitHub Desktop.
JS: Cross-domain jQuery JSON AJAX alternative for IE
// The ajax.php file must also return header('Access-Control-Allow-Origin: *');
if ($.browser.msie && window.XDomainRequest) {
// Use Microsoft XDR
var xdr = new XDomainRequest();
xdr.open("POST", js_base_url + 'ajax?id='+id);
xdr.onload = function () {
var JSON = $.parseJSON(xdr.responseText);
alert(JSON.response);
};
xdr.send();
} else {
$.ajax({
type: 'POST',
url: js_base_url + 'ajax',
data: {id: id},
dataType: 'json',
success: function(data) {
alert(data.response);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment