Creation of XMLHttpRequest objects

Source: Internet
Author: User
first introduce the XMLHttpRequest object, we all know that Ajax is not a single technology, but a combination of several technologies. XMLHttpRequest is the most core technology in the Ajax technology system, and without xmlhttprequest,ajax the rest of the technology cannot become an organic whole. In an AJAX application, the XMLHttpRequest object is responsible for sending the user information asynchronously to the server and receiving the response information and data returned by the server.

XMLHttpRequest when an object of the XMLHTTP component is used, the XMLHttpRequest can be implemented to partially update the page information without submitting the entire page to the server. May say that a little abstract, we are often into the QQ space to see friends dynamic, some friends to share the video, we click to play after the video buffer or during the playback of the mouse and keyboard are not incapacitated, we can continue to browse other dynamic, and we are sliding the mouse wheel up and down, The video page also moves up and down with the current location of our browsing, as shown in this function, which can be implemented via Ajax.

The XMLHttpRequest object provides a series of properties and methods to send asynchronous HTTP requests to the server. As the server processes user requests, the XMLHttpRequest object reflects the state of the HTTP request in real time through the state value of the property and directs the JavaScript to the appropriate processing based on the resulting state. In addition, when the server responds smoothly to user actions and returns the user, the response series method provided by XMLHttpRequest can assemble the returned data into a text format, an XML format, or a JavaScript script that is provided in the unsigned byte data format.

Before you use the XMLHttpRequest object to send requests and process responses, you must use JavaScript to create XMLHttpRequest objects. Because the XMLHttpRequest object is not currently a standard, the method of creation in the new version IE browser, the old version IE browser and non-IE browser is different. Therefore, you need to determine the type of browser before you create the XMLHttpRequest object. For the lower version of IE browser need to use Microsoft.XMLHTTP, and for the higher version of IE browser need to use Msxml2.xmlhttp.

Here's the code to create the XMLHttpRequest object:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" >    <script language= "javascript" type= "Text/javascript" >        var xmlHttp;        Create a XMLHttpRequest object with the new version of IE        try {            xmlHttp = new ActiveXObject ("Msxml2.xmlhttp");        } catch (e) {            // Create a XMLHttpRequest object with an older version of IE            try {                xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");            } catch (E) {}        }< c11/>//creating XMLHttpRequest objects using other browsers        if (!xmlhttp && typeof XMLHttpRequest! = ' undefined ') {            try{                Xmlhttp=new XMLHttpRequest ();            } catch (e) {                xmlHttp = false;            }        }    </script></span>


As we can see from the code, it is not complicated to create XMLHttpRequest objects, although logical judgments are required. Their understanding of the XMLHttpRequest is not very thorough, just according to the video examples and AJAX programming technology textbooks in the knowledge of the collation, I hope we can communicate more and common progress.

The above is the creation of XMLHttpRequest object content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.