Created
November 27, 2013 03:16
-
-
Save lyonsun/7670169 to your computer and use it in GitHub Desktop.
cross-browser XMLHttpRequest instantiation
This file contains hidden or 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
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