[Reprinted] Method for retrieving XMLHTTP objects in Ajax

Source: Internet
Author: User

Source: Empty http://www.cnblogs.com/doll-net/archive/2007/03/13/673309.html

There are many ways to get XMLHTTP objects. The following are my actual usage and collected on the Internet;
In actual use, it is generally written in a class and put in a single file separately; a new object is used; errors are avoided when multiple objects are used at the same time.

1 Function XMLHTTP ()
2 {
3 VaR XMLHTTP =   False ;
4 Try  
5 {
6XMLHTTP= NewActivexobject ("Msxml2.xmlhttp");
7}  
8 Catch (E)
9 {
10 Try  
11 {
12XMLHTTP= NewActivexobject ("Microsoft. XMLHTTP");
13}  
14 Catch (E2)
15 {
16XMLHTTP= False;
17}
18 }
19 If ( ! XMLHTTP &&   Typeof XMLHttpRequest ! = 'Undefined ')
20 {
21XMLHTTP= NewXMLHttpRequest ();
22}
23 Return XMLHTTP;
24 }

 

Function XMLHTTP () {
VaR XMLHTTP;
VaR Msxmlhttp =   New Array (
'Msxml2. XMLHTTP. 5.0 ',
'Msxml2. XMLHTTP. 4.0 ',
'Msxml2. XMLHTTP. 3.0 ',
'Msxml2. xmlhttp ',
'Microsoft. xmlhttp ');
For ( VaR I =   0 ; I < Msxmlhttp. length; I ++ ) {
Try   {
XMLHTTP= NewActivexobject (msxmlhttp [I]);
}   Catch (E) {
XMLHTTP= Null;
}
}

If ( ! XMLHTTP &&   Typeof XMLHttpRequest ! =   " Undefined " )
XMLHTTP  =   New XMLHttpRequest ();
Return XMLHTTP;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.