The initial experience of XMLHTTP object application development

Source: Internet
Author: User
Tags object contains modify requires return string client
The Xml| object MSXML provides a Microsoft.XMLHTTP object that completes the conversion from the packet to the request object and sends 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:

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 has been loaded 2 XML document already loaded, processing 3 parts XML document has been resolved 4 document has been resolved, client can accept 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

The following is a 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.

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 ......... ..............

[1] [2] Next page



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.