Last active
August 29, 2015 14:13
-
-
Save N8-B/4d60e49acaea9910118f to your computer and use it in GitHub Desktop.
XMLHttpRequest in IE6
This file contains 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
// An alternative implementation to the createXHR function for creating | |
// an XHR object in all modern browsers as well as emulating IE5 and IE6. | |
if (window.XMLHttpRequest === undefined) { | |
window.XMLHttpRequest = function() { | |
try { | |
// Use the latest version of the ActiveX object if available | |
return new ActiveXObject("Msxml2.XMLHTTP.6.0"); | |
} | |
catch(e1) { | |
try { | |
// Otherwise fall back to older version | |
return new ActiveXObject("Msxml2.XMLHTTP.3.0"); | |
} | |
catch(e2) { | |
// But if the older version is not available, throw an error | |
throw new Error("XMLHttpRequest is not supported"); | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment