MSXML provides the Microsoft.XMLHTTP object, which can complete the conversion and sending tasks from data packets to Request objects.
The statement to create an 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")
After the object is created, call the Open method to initialize the Request object. The syntax format is:
poster.open http-method, url, async, userID, password.
The Open method contains 5 Parameters, the first three are required, the last two are optional (provided when the server requires authentication). The meaning of the parameters is as follows:
http-method: HTTP communication method, such as GET or POST
url: The URL address of the server that receives XML data. Usually the ASP or CGI program async is specified in the URL
: a Boolean flag indicating whether the request is asynchronous. If it is an asynchronous communication mode (true), the client does not wait for the server's response; if it is a synchronous mode (false), the client has to wait until the server returns a message before performing other operations
userID user ID, used for server authentication
password User password, used for server authentication.
The Send method of the XMLHTTP object
uses the Open method to initialize the Request object, and then calls the Send method to send the XML data:
poster.send XML-data.
The parameter type of the Send method is Variant, which can be a string or DOM. tree or arbitrary data stream. There are two ways to send data: synchronous and asynchronous. In asynchronous mode, once the data packet is sent, the Send process is ended, and the client performs other operations; in synchronous mode, the client waits until the server returns a confirmation message before ending the Send process.
The readyState attribute in the XMLHTTP object can reflect the progress of the server in processing the request. The client program can set the corresponding event processing method based on this status information. The attribute values and their meanings 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 The XML document has been loaded
2 The XML document has been loaded and is being processed.
3 Part of the XML document has been parsed
4 The document has been parsed and the client can accept the return message.
The client processes the response information.
After receiving the return message, the client performs simple processing, which basically completes an interaction cycle between C/S. The client receives the response through the attributes of the XMLHTTP object:
● responseTxt: treats the return message as a text string;
● responseXML: treats the return message as an XML document, used when the server response message contains XML data;● responseStream: treats the return message
as an XML document
The returned message is treated as a Stream object
------this is the following very simple JAVASCRIPT function SEND(STR,URL)---------------
XMLDOM and XMLHTTP objects are used. The advantage of using this technology is: full JS control, convenient/simple, much better than RDS or remote. (Prerequisite: both the server and client must have IE5 or higher installed), the no-refresh online information I posted The function also uses this technology. Friends who are interested can take a look..
function Send(Str,URL)
//The STR parameter is the XML data passed in. You can also pass in other text data.
//However, this function needs to be processed by the server and returned to XML data. You can also modify it.
//URL parameter represents the ASP file address of the data you want to process
{
var Http = new ActiveXObject("Microsoft.XMLHTTP") //Create an XMLHTTP object var Dom = new ActiveXObject("Microsoft.XMLDOM") //Create an XMLDOM object Http.open("POST",URL,false)
//The first parameter means to send data using "POST" method. It can be up to 4MB, or it can be changed to "GET". It can only be 256KB
//The second parameter means which file the data is sent to for processing //The third parameter means synchronous or asynchronous mode. TRUE means asynchronous, FALSE means synchronous Http.send(Str) //Start sending data.... .........beep..
Dom.async=false //Set to obtain data synchronously Dom.loadXML(Http.responseText)
//Start to obtain the data returned after server-side processing. The settings I set here must be XML data, otherwise an error will occur.
//You can also modify it yourself so that the returned data is binary or recordset data............................. ..
if(Dom.parseError.errorCode != 0) //Check whether an error occurs while obtaining data{
delete(Http)
delete(Dom)
return(false)
}
else
{
var Back = Dom.documentElement.childNodes.item(0).text
//Get the returned XML data. I assume here that the handler only returns one row of XML data (one node)
delete(Http)
delete(Dom)
return(Back) //Function returns data.............End}
}
VAR CAT = Send("<User Information><Name>Xie Meng</Name></User Information>"," HTTP://WWW.CHINAASP.COM/VIVA.ASP ") //Execute function
IF(CAT == FALSE)
{
ALERT("Sorry. The handler returned FALSE. Data processing has failed...")
}
ELSE
{
IF(EVAL(CAT))
{
ALERT("OK. The data has been sent successfully. And the processing is completed!!!!!!")
}
ELSE
{
ALERT("Sorry. The handler returned 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("<Program processing result><Final result>FALSE</Final result></Program processing result>")
ELSE
SET MOMO = BOBO.DOCUMENTELEMENT
IF MOMO.CHILDNODES.ITEM(0).TEXT = "Xie Meng" THEN
RESPONSE.WRITE("<Program processing result><Final result>TRUE</Final result></Program processing result>")
ELSE
RESPONSE.WRITE("<Program processing result><Final result>FALSE</Final result></Program processing result>")
END IF
END IF
SET BOBO = NOTHING