XMLHTTP---Introduction

Source: Internet
Author: User
Tags contains final modify requires
XML MSXML provides a Microsoft.XMLHTTP object that completes transitions from packets to request objects and sends tasks.
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:
Poster.send 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 Response object has been created, but the XML document upload process has not yet ended
1 XML document already loaded
2 XML document already loaded, in process
3 Part XML document has 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 technology are: Full JS control, easy/simple, than RDS
Or remote is much better. (Prerequisite: Server-side and client must be installed IE5 or later), in my posted
The same technique is used for the No Refresh online information feature. Interested friends can see.
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



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.