Ajax. Request () Explanation

Source: Internet
Author: User

Ajax. Request (URL, {method: method, parameters: Para, postbody: xmlstring, asynchronous: True, setRequestHeader: object, oncomplete: completefun, onerror: errorfun}) sends an asynchronous request. (This method is written to be compatible with prototype. js. The Calling style is the same as that of prototype. Use Ajax. Request to load this JS file on the page)

The URL parameter is required. The destination address of the data transmission.

Method option. Data submission method. The default value is get. There are also commonly used post.

Parameters is optional when method is get and post. The data sent in the form of name1 = valeu1 & name2 = value2 & name3 = value3. ...... postbody option. The XML format string sent by the client. If postbody is enabled, parameters is ignored. Asynchronous is optional. Specifies whether the request is asynchronous. The default value is true (asynchronous ). SetRequestHeader specifies the request header string. Its value type is an object in the form of "name value pair", for example: {"If-modified-since": "0", "soapaction ": "http://tempuri.org/SBS_WebService ",......} oncomplete option. The callback function executed when the request is successful. By default, the current XMLHTTP object is used as the first parameter. Onerror is optional. The callback function executed when a request exception occurs. By default, the current XMLHTTP object is used as the first parameter. Return the XMLHTTP object currently used.

Description used to send an asynchronous request and return an XMLHTTP object. The object has a built-in abort () method used to terminate the request in advance. If the asynchronous request is successful, oncomplete is executed, and if the request fails, onerror is executed. And return the XMLHTTP object. Ajax. Request is a complete Ajax method of interfaces and is the core method of all other Ajax methods in myjsframe.

Example 1: <SCRIPT type = "text/JavaScript">

VaR myajax = new Ajax. request ("http://www.happyshow.org/form.asp", {method: "Post", // form submission method parameters: "name = acai & age = 26 & sex = male", // submit form data

SetRequestHeader: {"If-modified-since": "0"}, // disable reading cached data

Oncomplete: function (x) {// callback after successful submission

Alert (X. responsetext) ;}, onerror: function (x) {// callback for submission failure

Alert (X. statustext );}});

</SCRIPT>

NOTE: If parameters are not listed, we can process data such as Form in development.

Parameters: form. serialize ('formname') formname is the form ID on the page.

 

Example 2: <SCRIPT type = "text/JavaScript">

VaR xmlstring = "<root>" + "<people> <Name> caizhongqi </Name> <sex> male </sex> </People>" + "<people> <name> ahuang </Name> <sex> female </sex> </People> "+" </root> ";

VaR myajax = new Ajax. Request ("http://www.happyshow.org/xmlform.asp ",

{Method: "Post", // form submission method

Postbody: xmlstring, // submitted XML

SetRequestHeader: {"Content-Type": "text/XML"}, // specify the data to be sent as an XML document (non-string)

Oncomplete: function (x) {// callback after successful submission

Alert (X. responsexml. XML );},

Onerror: function (x) {// callback for submission failure

Alert (X. statustext );}});

</SCRIPT>

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.