XMLHTTP --- Introduction

xiaoxiao2021-03-06  70

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:

Set objxml = creteObject ("msxml2.xmlhtp") or

Set objxml = creteObject ("Microsoft.xmlhttp")

'OR, for Version 3.0 of XMLHTTP, USE:

'Set XML = Server.createObject ("msxml2.serverxmlhttp")

The OPEN method is called after the object is created, and the REQUEST object is initialized. The syntax format is:

Poster.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 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 you want to specify an ASP or CGI program in the URL

ASYNC: A Boolean identifier indicating whether the request is asynchronous. If it is asynchronous communication mode, the client will not wait for the server's response; if it is a synchronization mode (FALSE), the client will wait until the server returns a message before performing 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 XML data:

Poster.send XML-Data

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 is already loaded

2 XML document is already loaded, it is processing

3 section XML document has been parsed

4 Documents have been parsed, and the client can accept the return message.

Client Processive Response Information

After receiving the return message, the client is received, and there is basically 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: Treat the return message as an XML document, use XML data in the server response message;

● ResponseStream: Treats the return message as a stream object

------ is this very simple JavaScript function Send (STR, URL) ---------------

Used is XMLDOM and XMLHTTP objects. The benefits of this technology are: full JS control, convenient / simple, than RDS

Or Remote is much more. (Prerequisite: both the server side and the client must install IE5 or higher), in the sticked

This technology is also using this technology. Interested friends can take a look..

The Function Send (STR, URL) // STR parameter is incoming XML data, and you can also pass other text data.

/ / However, this function returns XML data after the server is handled, you can also modify it.

// URL parameter indicates an ASP file address you want to process data.

{

Var http = new activXObject ("Microsoft.xmlhttp") // Establish an XMLHTTP object

VAR DOM = New ActiveXObject ("Microsoft.xmLDom") // Established an XMLDOM object

Http.Open ("POST", URL, FALSE

// The first parameter means that data is transmitted in the "POST" mode. It can be large to 4MB, or it can be changed to "get". Can only 256kb

// The second parameter means which file processing is sent to

// The third parameter means synchronous or asynchronous mode. True is asynchronous, false is synchronous

Http.send (str) // Start sending data ........... Dudu ..

Dom.async = false // Set to synchronize how to get data

Dom.LoadXML (http.responsext)

// Start getting the data returned after the server is processed. I have an XML data here, otherwise I'm wrong.

// You can also modify it yourself. Make it to return 2 credits or record set data ........................... .

if (Dom.Parseerror.ErrorCode! = 0) // Checks if it is incorrectly

{

Delete (http)

Delete (DOM)

Return (false)

}

Else

{

Var back = dom.documentelement.childnodes.Item (0) .text

/ / Get the return XML data, I assume that the handler only returns a line XML data (a node)

Delete (http)

Delete (DOM)

Return (back) // function returns data .....................

}

}

Var cat = send (" Xie Lemon ", "

Http://www.chinaasp.com/viva.asp ") // Execute function

IF (CAT == FALSE)

{

Alert ("Sorry. The handler returns false. Data processing has failed ...")

}

Else

{

IF (EVAL (CAT))

{

Alert ("OK. Data has been sent success.) Is completed !!!!!!")

}

Else

{

Alert ("Sorry. The handler returns false. Data processing has failed ...")

}

}

=============================== ==================== ============

ON Error ResMe next

DIM BOBO

DIM MOMO

Set Bobo = Server.createObject ("Microsoft.xmLDom")

BOBO.ASYNC = FALSE

BOBO.LOAD REQUESTIF BOBO.PARSEERROR.ERRORCODE <> 0 THEN

Response.write (" false )

Else

Set momo = bobo.documentelement

If Momo.childnodes.Item (0) .text = "Xie Lemon" THEN

Response.write (" True ")

Else

Response.write (" false )

END IF

END IF

SET BOBO = Nothing

转载请注明原文地址:https://www.9cbs.com/read-89588.html

New Post(0)