Last active
August 29, 2015 14:16
-
-
Save mzabriskie/60c0e30b00e1ab875e16 to your computer and use it in GitHub Desktop.
Creating cross browser XHR object
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
| function createXHR() { | |
| if (!createXHR.__memoize) { | |
| var factory = [ | |
| function () {return new XMLHttpRequest()}, | |
| function () {return new ActiveXObject("Microsoft.XMLHTTP")}, | |
| function () {return new ActiveXObject("Msxml3.XMLHTTP")}, | |
| function () {return new ActiveXObject("Msxml2.XMLHTTP")}, | |
| ]; | |
| var xhr; | |
| for (var i=0, l=factory.length; i<l; i++) { | |
| try { xhr = factory[i](); } catch (e) { continue; } | |
| createXHR.__memoize = factory[i]; | |
| break; | |
| } | |
| return xhr; | |
| } | |
| return createXHR.__memoize(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment