Recently, many users have used this method when asking questions about Ajax application in IE. Code :
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
I won't check where the code was copied, but it is problematic, at least it is outdated for most client systems.
Microsoft's support for XMLHTTP is not limited to browsers, but for the entire system and allProgramIn the form of COM components, there have been many versions, we listed in order as follows:
The new COM component (DLL) contains previous versions (backward compatible ).
Progid = Microsoft. xmlhttp.1.0
Guid = {ED8C108E-4349-11D2-91A4-00C04F7969E8}
Typelib = {D63E0CE2-A0A2-11D0-9C02-00C04FC99C8E}
Versionindependentprogid = Microsoft. XMLHTTP
Located in C: "Windows" System32 "MSXML. dll
Progid = msxml2.xmlhttp. 2.6
Guid = {f5078f1e-c551-11d3-89b9-0000f81fe221}
Typelib = {f5078f18-c551-11d3-89b9-0000f81fe221}
Versionindependentprogid = msxml2.xmlhttp
Located in C: "Windows" System32 "msxml2.dll
Progid = msxml2.xmlhttp. 3.0
Guid = {F5078F35-C551-11D3-89B9-0000F81FE221}
Typelib = {F5078F18-C551-11D3-89B9-0000F81FE221}
Versionindependentprogid = msxml2.xmlhttp
Located in C: "Windows" System32 "msxml3.dll
Progid = msxml2.serverxmlhttp. 3.0
Guid = {AFB40FFD-B609-40A3-9828-F88BBE11E4E3}
Typelib = {F5078F18-C551-11D3-89B9-0000F81FE221}
Versionindependentprogid = msxml2.serverxmlhttp
Located in C: "Windows" System32 "msxml3.dll
Progid = msxml2.xmlhttp. 4.0
Guid = {88d969c5-f192-11d4-a65f-0040963251e5}
Typelib = {F5078F18-C551-11D3-89B9-0000F81FE221}
No versionindependentprogid
Located in C: "Windows" System32 "msxml4.dll
Progid = msxml2.serverxmlhttp. 4.0
Guid = {88d969c6-f192-11d4-a65f-0040963251e5}
Typelib = {F5078F18-C551-11D3-89B9-0000F81FE221}
No versionindependentprogid
Located in C: "Windows" System32 "msxml4.dll
Progid = msxml2.xmlhttp. 5.0
Guid = {88d969ea-f192-11d4-a65f-0040963251e5}
Typelib = {F5078F18-C551-11D3-89B9-0000F81FE221}
No versionindependentprogid
Located in C: "Program Files" common files "Microsoft shared" office11 "msxml5.dll
Progid = msxml2.serverxmlhttp. 5.0
Guid = {88d969eb-f192-11d4-a65f-0040963251e5}
Typelib = {F5078F18-C551-11D3-89B9-0000F81FE221}
No versionindependentprogid
Located in C: "Program Files" common files "Microsoft shared" office11 "msxml5.dll
In general, the new version has fewer errors than the old version, and the performance is better. Sometimes some unexpected problems or poor efficiency are the bugs in the old version, which may have been improved in the new version. Therefore, we should give priority to the latest version.
ActiveX objects like new activexobject ("Microsoft. XMLHTTP") Call version 1.0 (the oldest version ).
The more common new activexobject ("msxml2.xmlhttp") calls versions 2.6 or 3.0 (if the client has a newer version, it calls a newer version, view the value of the hkey_classes_root "msxml2.xmlhttp" curver project in the registry. For version 3.0, the value is "msxml2.xmlhttp. 3.0 ".)
To call an updated version, you must specify the version number, that is, use the progid listed above. For example, version 5.0 is new activexobject ("msxml2.xmlhttp. 5.0 ").
Recommended Syntax:
VaR XMLHTTP = NULL;
If (window. XMLHttpRequest)
{
XMLHTTP = new XMLHttpRequest ();
}
If (! XMLHTTP & window. activexobject)
{
Try
{
XMLHTTP = new activexobject ("msxml2.xmlhttp. 5.0 ")
}
Catch (E)
{
Try
{
XMLHTTP = new activexobject ("msxml2.xmlhttp. 4.0 ")
}
Catch (e ){
Try
{
New activexobject ("msxml2.xmlhttp ")
}
Catch (E)
{
Try {
New activexobject ("Microsoft. XMLHTTP ")
} Catch (e ){
}
}
}
}
}
If (! XMLHTTP) {alert ("XMLHTTP is unavailable. The webpage is about to jump to a non-Ajax page. "); Location =" nonajax.htm "}
Try ...... The catch statement is not supported in ie4.0 and earlier versions of IE browsers (when the script5.6 engine is not installed. However, there should be very few such old systems. Moreover, we do not have the need to support Ajax on antique clients-anyone who can come up with such odd requirements should be artists and pursue Van Gogh's path.
In versions 3.0 and later, there is a corresponding serverxmlhttp.
In addition to the original methods of XMLHTTP, serverxmlhttp also supports the following methods:
Settimeouts (resolvetimeout: I4; connecttimeout: I4; sendtimeout: I4; receivetimeout: I4 );
Waitforresponse ([timeoutinseconds: variant]): bool;
Getoption (option: serverxmlhttp_option): variant;
Setoption (option: serverxmlhttp_option; Value: variant );
Setproxy (proxysetting: sxh_proxy_setting; [varproxyserver: variant; varbypasslist: variant]);
Setproxycredentials (bstrusername: BSTR; bstrpassword: BSTR );
In other words, you can set timeout, additional options, and select the proxy server on your own. However, you cannot use local cookies or some HTTP 1.1 features. For details, refer to msdn.
In IE7 +, the embedded XMLHTTPRequest object is used.
If (window. XMLHttpRequest)
{
VaR oreq = new XMLHttpRequest ();
Oreq. Open ("get", "http: // localhost/test. xml ");
Oreq. Send ();
Alert (oreq. statustext );
}