Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
Last active February 27, 2023 18:09
Show Gist options
  • Save sTiLL-iLL/55ab4345eb49e7a8f2ca to your computer and use it in GitHub Desktop.
Save sTiLL-iLL/55ab4345eb49e7a8f2ca to your computer and use it in GitHub Desktop.
XHR and fallback
// 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