-
-
Save subzey/991713 to your computer and use it in GitHub Desktop.
/* arguments are defined but ignored */ | |
function(s, a){ | |
/* | |
Here: | |
a = "Msxml2.XMLHTTP" | |
((anonymous array)) = ["Msxml2.XMLHTTP"] | |
((anonymous array)) = ["Msxml2.XMLHTTP", "Msxml2.XMLHTTP.3.0"] | |
((anonymous array)) = ["Msxml2.XMLHTTP", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP.6.0"] | |
a = ((that anonymous array)) | |
*/ | |
a = [a = "Msxml2.XMLHTTP", a + ".3.0", a + ".6.0"]; | |
do /* try..catch do not requires {} */ | |
try { | |
/* | |
Get the last element, so during the loop s variable is: | |
"Msxml2.XMLHTTP.6.0" | |
"Msxml2.XMLHTTP.3.0" | |
"Msxml2.XMLHTTP" | |
undefined | |
*/ | |
s=a.pop(); | |
/* try to return new... */ return new /* ... XHR if s==undefined (last iteration), AX if not */ (s ? ActiveXObject : XMLHttpRequest) /*... using s itself as an argument */(s) | |
} catch(e){ | |
/* if it is failed do nothing and leave ; for very old version of Firefox */; | |
} | |
/* if s == undefined (and a.length == 0) that was a last iteration and exit */ | |
while(s) | |
/* thats it, return undefined if all previous return attempts failed */ | |
} |
function(s,a){a=[a="Msxml2.XMLHTTP",a+".3.0",a+".6.0"];do try{s=a.pop();return new(s?ActiveXObject:XMLHttpRequest)(s)}catch(e){;}while(s)} |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
{ | |
"name": "crossbrowser_XHR", | |
"description": "Function creates XMLHTTPRequest object in IE6+ and other browsers.", | |
"keywords": [ | |
"xhr" | |
] | |
} |
It is tested in IE 6..9, Firefox, Opera, Chrome.
(IE6 is tested 3 times on different PCs)
Also, this should work in any future browser that implements XMLHttpRequest constructor.
awesome work, this will definitely come in handy.
hey @subzey, could you take the comments out of your package.json?
catch(e){;}
- the semicolon is superfluous here - and do while can be replaced with a for loop:
function(s,a){for(a=[a="Msxml2.XMLHTTP",a+".3.0",a+".6.0"];;)try{s=a.pop();return new(s?ActiveXObject:XMLHttpRequest)(s)}catch(e){}}
The use of various ActiveX progIDs is pretty misunderstood.
You can check out this rad 3 page thread on the topic (read through all pages, it's a bit old but does the job).
To be honest I don't know the benefit of using 6.0
over 3.0
vs plain MSXML2.XMLHTTP
, the post does explain some possible differences between MSXML2.XMLHTTP
and Microsoft.XMLHTTP
though.
In practice jQuery seems to be doing fine with just using Microsoft.XMLHTTP
.
is this reliable? closest thing i've found is this.