XMLHttp object is used in Ajax. I have seen various methods of getting this object, and I think this method is the most elegant. First, consider the appropriate browser; second, consider the priority Loading Order, from the high version to the lower version test, and finally if not found, throw an exception. FunctionFactory... SyntaxHighlighter. all ();
XMLHttp object is used in Ajax. I have seen various methods of getting this object, and I think this method is the most elegant. First, consider the appropriate browser; second, consider the priority Loading Order, from the high version to the lower version test, and finally if not found, throw an exception.
Function FactoryXMLHttpRequest (){
If (window. XMLHttpRequest ){
Return new XMLHttpRequest ();
} Else if (window. ActiveXObject ){
Var msxmls = new Array (
'Msxml2. XMLHTTP.5.0 ',
'Msxml2. XMLHTTP.4.0 ',
'Msxml2. XMLHTTP.3.0 ',
'Msxml2. xmlhttp ',
'Microsoft. xmlhttp ');
For (var I = 0; I <msxmls. length; I ++ ){
Try {
Return new ActiveXObject (msxmls [I]);
} Catch (e ){
}
}
}
Throw new Error ("cocould not instantiate XMLHttpRequest ");
}
From the column hongweigg