-
-
Save subzey/991713 to your computer and use it in GitHub Desktop.
140byt.es Cross-browser XHR
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
| /* 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 */ | |
| } |
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(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)} |
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
| 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. |
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
| { | |
| "name": "crossbrowser_XHR", | |
| "description": "Function creates XMLHTTPRequest object in IE6+ and other browsers.", | |
| "keywords": [ | |
| "xhr" | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.0over3.0vs plainMSXML2.XMLHTTP, the post does explain some possible differences betweenMSXML2.XMLHTTPandMicrosoft.XMLHTTPthough.In practice jQuery seems to be doing fine with just using
Microsoft.XMLHTTP.