Microsoft.xmlHTTP objects are provided in MSXML to complete the conversion from packets to the REQUEST object, and send tasks. Creating a statement for the XMLHTTP object is as follows:
Var http = new activXObject ("Microsoft.xmlhttp");
After the object is created, call the Open method to initialize the Request object, the syntax format is: http .Open (http-method, url, async, userid, password);
The OPEN method contains 5 parameters, the top three are necessary, the latter two are optional (provided when the server needs to be authenticated). The meaning of the parameter is as follows: http-method: HTTP communication method, such as a GET or POST URL: The URL address of the server that receives XML data. Typically in the URL to indicate an ASP or CGI program async: a Boolean identity, indicating whether the request is asynchronous. If it is asynchronous communication mode (TRUE), the client will not wait for the server response; if it is a synchronous mode (FALSE), the client will wait until the server returns the message to perform other operations Userid: User ID, for server authentication Password: User Password for Server Authentication
XMLHTTP object SEND method
After initialization of the Request object with the Open method, call the Send method to send a request:
Http .send ()
The parameter type of the Send method is Variant, which can be a string, a DOM tree, or any data stream. The way to send data is divided into synchronous and asynchronous. In an asynchronous mode, once the data package is sent, end the Send process, the client performs other operations; and in the synchronization mode, the client will wait until the server returns a confirmation message to end the Send process. The ReadyState property in the XMLHTTP object reflects the progress of the server during processing the request. The program of the client can set the corresponding event processing method according to this status information. The attribute value and its meaning are shown in the following table: Value Description
0 Response object has been created, but the XML document upload process has not ended 1 XML document has been loaded. 2 XML documents have been loaded. It is handling 3 part XML documents has parsed 4 documents have been parsed, and the client can accept return message.
After the client processing response information client receives the return message, the simple processing is made substantially a interactive cycle between C / S. The client receiving response is implemented by the properties of the XMLHTTP object:
ResponseTxt: The message will return as a text string; responsexml: Use the return message as an XML document, use XML data in the server response message; responsestream: Treat the return message as a stream object
------ A simple JavaScript example, will get XML text generation word xmldom object --------------- var http = new activExObject ("Microsoft.xmlhttp"); var URL = 'getiteml.jsp? id = 1'; // This page From the number of databases and generates the return specification XML text http.open ("post", URL, FALSE); http.send (); var xmldoc = New ActiveXObject ("msxml.domdocument"); xmldoc.async = false; xmldoc.loadXML (http.responsetext);