Last active
February 27, 2023 18:09
-
-
Save sTiLL-iLL/55ab4345eb49e7a8f2ca to your computer and use it in GitHub Desktop.
XHR and fallback
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
// simple request with a fallback | |
function getXHR() { | |
if (window.XMLHttpRequest) { | |
return new XMLHttpRequest(); | |
} | |
try { | |
return new ActiveXObject('MSXML2.XMLHTTP.6.0'); | |
} | |
catch (err) { | |
try { | |
// fallback. | |
return new ActiveXObject('MSXML2.XMLHTTP.3.0'); | |
} | |
catch (err) { | |
alert('AJAX is not enabled.'); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment