Core XMLHTTP objects and methods of AJAX

Source: Internet
Author: User

XMLHTTP object and its method
------------------
MSXML provides Microsoft. XMLHTTP objects, which can complete conversion from data packets to request objects and send tasks.
The statement for creating 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, the open method is called to initialize the request object. The syntax format is:
Poster. Open http-method, URL, async, userid, password
The open method contains five parameters, the first three are necessary, and the last two are optional (provided when the server requires authentication ). The parameter meanings are as follows:
HTTP-method: the communication method of HTTP, such as get or post.
URL: the URL of the server that receives XML data. The ASP or CGI program is usually specified in the URL.
Async: A boolean identifier indicating whether the request is asynchronous. If it is an asynchronous communication method (true), the client will not wait for the server's response; if it is a synchronous mode (false), the client will wait until the server returns a message to execute other operations
Userid, used for Server Authentication
Password, used for Server Authentication
Send method of XMLHTTP object
After initializing the request object using 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, DOM tree, or any data stream. Data transmission methods can be synchronous or asynchronous. In asynchronous mode, once a packet is sent, the send process is terminated and the client performs other operations. In synchronous mode, the client waits until the server returns a confirmation message to terminate the send process.
The readystate attribute in the XMLHTTP object can reflect the progress of the server when processing requests. The client program can set corresponding event handling methods based on the status information. The attribute values and their meanings are shown in the following table:
Value description
0 response object has been created, but the XML Document Upload process has not been completed
1. the XML document has been loaded.
2. the XML file has been loaded and is being processed.
3. Some XML documents have been parsed.
4. The file has been parsed and the client can accept the returned message.
The client processes response information.
After the client receives the returned message, it simply processes it and basically completes an interaction cycle between C/S. The client receives the response through the attributes of the XMLHTTP object:
● Responsetxt: Use the returned message as a text string;
● Responsexml: regards the returned message as an XML document, which is used when the server response message contains XML data;
● Responsestream: regards the returned message as a stream object.
 

The following XML file is dynamically generated and finally transmitted using XMLHTTP. This is a content in the client Javascript script. Of course, you can also write it on the server, however, we need to modify the following items: (for your reference only and learn about its usage)
VaR xmldoc = new activexobject ("msxml2.domdocument ");
Flag = xmldoc. loadxml ("");

Newnode = xmldoc. createelement ("encoding ")
Marknodeappsxmldoc.doc umentelement. appendchild (newnode );
Newnode = xmldoc. createelement ("startmark ")
Newnode. Text = startmark;
Marknode. appendchild (newnode)
Newnode = xmldoc. createelement ("endmark ")
Newnode. Text = endmark;
Marknode. appendchild (newnode)

Newnode = xmldoc. createelement ("date ")
Datenodemo-xmldoc.doc umentelement. appendchild (newnode );
Newnode = xmldoc. createelement ("startdate ");
Newnode. Text = startdate;
Datenode. appendchild (newnode)
Newnode = xmldoc. createelement ("enddate ")
Newnode. Text = enddate;
Datenode. appendchild (newnode );

Newnode = xmldoc. createelement ("quantity ")
Slnode upload xmldoc.doc umentelement. appendchild (newnode );
Newnode = xmldoc. createelement ("startsl ")
Newnode. Text = startshul
Slnode. appendchild (newnode)
Newnode = xmldoc. createelement ("endsl ");
Newnode. Text = endshul
Slnode. appendchild (newnode );

Newnode = xmldoc. createelement ("unit price ")
Djnode uses xmldoc.doc umentelement. appendchild (newnode)
Newnode = xmldoc. createelement ("startdj ")
Newnode. Text = startdanj;
Djnode. appendchild (newnode );
Newnode = xmldoc. createelement ("enddj ")
Newnode. Text = enddanj;
Djnode. appendchild (newnode );

Newnode = xmldoc. createelement ("amount ")
Jenode uses xmldoc.doc umentelement. appendchild (newnode)
Newnode = xmldoc. createelement ("startje ")
Newnode. Text = startjine
Jenode. appendchild (newnode)
Newnode = xmldoc. createelement ("endje ")
Newnode. Text = endjine
Jenode. appendchild (newnode)

Newnode = xmldoc. createelement ("repository Code ")
Newnode. Text = CK;
Xmldoc.doc umentelement. appendchild (newnode)

Newnode = xmldoc. createelement ("Ticket No ")
Newnode. Text = rkph;
Xmldoc.doc umentelement. appendchild (newnode)

Newnode = xmldoc. createelement ("unit code ")
Newnode. Text = corpname;
Xmldoc.doc umentelement. appendchild (newnode)

Newnode = xmldoc. createelement ("biaoshi ")
Newnode. Text = biaoshi
Xmldoc.doc umentelement. appendchild (newnode)

Newnode = xmldoc. createelement ("findcate ")
Newnode. Text = findcate
Xmldoc.doc umentelement. appendchild (newnode)

VaR XH = new activexobject ("msxml2.xmlhttp ")
XH. Open ("Post", "Find. asp", false)
XH. setRequestHeader ("Content-Type", "text/XML ")
XH. setRequestHeader ("Content-Type", "gb2312 ")
XH. Send (xmldoc );
The text value of each newnode is a variable, that is, the input value in the form of the client,

Related Article

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.