Use XMLHTTP to retrieve XML documents and generate XMLDOM

Source: Internet
Author: User
MSXML provides Microsoft. XMLHTTP objects, which can complete conversion from data packets to Request objects and send tasks.
The statement for creating an XMLHTTP object is as follows:
Var Http = new ActiveXObject ("Microsoft. XMLHTTP ");
After the object is created, the Open method is called to initialize the Request object. The syntax format is:
 
Http. open (http-method, url, async, userID, password );
The Open method contains five parameters, the first three are necessary, and the last two are optional (provided when the server requires authentication ). The parameter meanings are as follows:
 
Http-method: the communication method of HTTP, such as GET or POST.
Url: The URL of the server that receives XML data. The ASP or CGI program is usually specified in the URL.
Async: a Boolean identifier indicating whether the request is asynchronous. If it is an asynchronous communication method (true), the client will not wait for the server's response; if it is a synchronous mode (false), the client will wait until the server returns a message to execute other operations
UserID: User ID, used for server authentication
Password: The user password used for server authentication.
Send method of XMLHTTP object
After initializing the Request object using the Open method, call the Send method to Send the Request:
Http. send ()
The parameter type of the Send method is Variant, which can be a string, DOM tree, or any data stream. Data transmission methods can be synchronous or asynchronous. In asynchronous mode, once a packet is sent, the Send process is terminated and the client performs other operations. In synchronous mode, the client waits until the server returns a confirmation message to terminate the Send process.
The readyState attribute in the XMLHTTP object can reflect the progress of the server when processing requests. The client program can set corresponding event handling methods based on the status information. The attribute values and their meanings are shown in the following table:
Value description
0 Response object has been created, but the XML document upload process has not been completed
1. The XML document has been loaded.
2. The XML file has been loaded and is being processed.
3. Some XML documents have been parsed.
4. The file has been parsed and the client can accept the returned message.
The client processes response information.

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.