Skip to content

Instantly share code, notes, and snippets.

@lyonsun
Created November 27, 2013 03:16
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 lyonsun/7670169 to your computer and use it in GitHub Desktop.
Save lyonsun/7670169 to your computer and use it in GitHub Desktop.
cross-browser XMLHttpRequest instantiation
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject () {
var xmlHttp;
if (window.ActiveXObject) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xmlHttp = false;
}
} else {
try {
xmlHttp = new XMLHttpRequest();
} catch(e) {
xmlHttp = false;
}
}
if (!xmlHttp) {
alert("Error creating the XMLHttpRequest object.");
} else {
return xmlHttp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment