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>