Ajax. Request (
URL,
{
Method: method,
Parameters: Para,
Postbody: xmlstring,
Asynchronous: True,
SetRequestHeader: object,
Oncomplete: completefun,
Onerror: errorfun
}
)
Send 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)
Parameters
URL
Required. The destination address of the data transmission.
Method
Optional. Data submission method. The default value is get. There are also commonly used post.
Parameters
It is optional when method is get and post. The sent data in the form of name1 = valeu1 & name2 = value2 & name3 = value3 ......
Postbody
Optional. The XML format string sent by the client. If postbody is enabled, parameters is ignored.
Asynchronous
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
Optional. The callback function executed when the request is successful. By default, the current XMLHTTP object is used as the first parameter.
Onerror
Optional. The callback function executed when a request exception occurs. By default, the current XMLHTTP object is used as the first parameter.
Return Value
The currently used XMLHTTP object.
Description
Sends an asynchronous request and returns the XMLHTTP object. The object has the abort () method built in 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
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", // submitted 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>