xml| objects
The Microsoft.XMLHTTP object is provided in MSXML to perform the conversion from the packet to the request object and to send the task.
The statement that creates the XMLHTTP object is as follows:
Set Objxml = CreateObject ("Msxml2.xmlhttp") or Set Objxml = CreateObject ("Microsoft.XMLHTTP") ' Or, for version 3.0 of XMLHTTP, use: ' Set XML = Server.CreateObject (' MSXML2. ServerXMLHTTP ") |
Invoke the Open method to initialize the request object after the object is created, in the form of the following syntax:
Poster.open http-method, url, async, UserID, password |
The Open method contains 5 parameters, the first three are necessary, and the last two are optional (provided when the server requires authentication). The meaning of the parameter is as follows:
Http-method:http means of communication, such as Get or POST
URL: The URL address of the server that receives the XML data. The ASP or CGI program is usually indicated in the URL
Async: A Boolean identifier that indicates whether the request is asynchronous. In the case of asynchronous communication (true), the client does not wait for a response from the server; if it is synchronous (false), the client waits for the server to return to the message before performing another operation
UserID user ID, for server authentication
Password user password for server authentication
Send method of XMLHTTP object
After you initialize the request object with the Open method, call the Send method to send the XML data:
The parameter type of the Send method is a variant, which can be a string, a DOM tree, or any stream of data. The way to send data is divided into two types: synchronous and asynchronous. In asynchronous mode, once the packet is sent, the send process is terminated, the client performs other actions, and in synchronous mode, the client waits until the server returns a confirmation message before the send process ends.
The readystate attribute in the XMLHTTP object can reflect the server's progress in processing the request. The client's program can set the corresponding event-handling method based on this state information. The property value and its meaning are shown in the following table:
Value |
Description |
0 |
The response object has been created, but the XML document upload process has not yet ended |
1 |
XML document already loaded |
2 |
The XML document is already loaded and processing |
3 |
Some XML documents have been parsed |
4 |
The document has been parsed and the client can accept the return message |
Client Processing Response Information
The client receives the return message, carries on the simple processing, basically completes an interaction period between C/S. The client receives the response through the properties of the XMLHTTP object:
Responsetxt: Returns the message as a text string;
Responsexml: The return message is treated as an XML document and is used when the server response message contains XML data;
Responsestream: Treats the return message as a Stream object
------is the following very simple JavaScript function send (Str,url)---------------
The XMLDOM and XMLHTTP objects are used. The benefits of this technique are: Full JS control, easy/simple, much better than RDS or remote. (Prerequisite: Server-side and client must be installed IE5 or later), this technique is used in the No Refresh online information feature I posted. Interested friends can look at.
function Send (Str,url) The str parameter is the incoming XML data, and you can also pass in other text data. However, this function requires server-side processing to return the XML data, you can also modify The URL parameter represents the ASP file address of the data you want to process { var Http = new ActiveXObject ("Microsoft.XMLHTTP")//Create XMLHTTP Object var Dom = new ActiveXObject ("Microsoft.XMLDOM")//Create XMLDOM Object Http.open ("POST", Url,false) The first argument means that the data is sent in "POST". can be as large as 4MB, can also be changed to "get". Only 256KB The 2nd parameter means which file the data is sent to processing The 3rd parameter means synchronous or asynchronous mode. True is asynchronous, false is synchronous Http.send (STR)//start sending the data ..... Doodle.. Dom.async=false//Set to get data synchronously Dom.loadxml (Http.responsetext) Starts getting the data returned after server-side processing. I'm here. Set must be XML data, otherwise error. You can also modify it yourself. Make the return of the 2 or recordset data ......... .............. if (Dom.parseError.errorCode!= 0)//check for errors when fetching data { Delete (Http) Delete (Dom) Return (false) } Else { var back = Dom.documentElement.childNodes.item (0). Text Get the returned XML data, I'm here to assume that the handler returns only one row of XML data (a node) Delete (Http) Delete (Dom) return (back)//function returns data .............. End } }
VAR CAT = Send ("< user information >< name > Xie Lemon </name ></user Data >", "HTTP://WWW.CHINAASP.COM/VIVA.ASP")//Executive function IF (CAT = = FALSE) { ALERT ("I'm sorry." The handler returns false. Data processing has failed ...) } ELSE { IF (EVAL (CAT)) { ALERT ("OK. Data has been sent successfully.) with the completion of processing!!!!!!") } ELSE { ALERT ("I'm sorry." The handler returns false. Data processing has failed ...) } }
===============================viva. asp============================ On ERROR RESUME NEXT DIM BOBO DIM Momo SET BOBO = SERVER. CreateObject ("MICROSOFT. XMLDOM ") BOBO. ASYNC = FALSE BOBO. LOAD REQUEST IF BOBO. ParseError. ErrorCode <> 0 THEN RESPONSE. WRITE ("< process results >< final results >false</final results ></program processing results >") ELSE SET Momo = BOBO. DocumentElement IF Momo. ChildNodes. ITEM (0). TEXT = "Xie Lemon" THEN RESPONSE. WRITE ("< process results >< final results >true</final results ></program processing results >") ELSE RESPONSE. WRITE ("< process results >< final results >false</final results ></program processing results >") End IF End IF SET BOBO = Nothing |