How to create an XMLHttpRequest object

Source: Internet
Author: User
Create an XMLHttpRequest object. Read the method for creating an XMLHttpRequest object. Method 1: We recommend that you create a Boolean variable varxmlhttp = false; // check whether IE browser is used. try {// if the JS version is later than 5 xmlhttp = newActiveXObject ("> <LINKhref

Method 1: recommended

// Create a Boolean variable

Var xmlhttp = false;

// Check whether IE browser is used

Try {

// If the JS version is later than 5

Xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP ");

Alert ("You are using Microsoft Internet Explorer .");

} Catch (e ){

// If not, ActiveX objects of earlier versions are used.

Try {

// If you are using IE

Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");

Alert ("You are using Microsoft Internet Explorer .");

} Catch (e ){

// Use a non-IE browser

Xmlhttp = false;

}

}

// If you are using an IE non-browser

If (! Xmlhttp & typeof XMLHttpRequest! = 'Undefined '){

Xmlhttp = new XMLHttpRequest ();

Alert ("You are not using Microsoft Internet Explorer .");

}

Method 2:

Var xmlhttp;
// If ActiveX objects are available, you must use IE browser.
(! Window. ActiveXObject ){
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
} Else {
// Use Javascript for processing
Xmlhttp = new XMLHttpRequest ();
}

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.