Reprinted from: http://www.cnblogs.com/beyondGodLike/archive/2009/08/04/1538543.html
The Ajax. Updater method has three parameters: Ajax. Updater (container, URL, options)
1. Control ID, 2. requested URL, and 3. Optional ):
Attribute |
Type |
Default |
Description |
Method |
Array |
'Post' |
HTTP request method. Get or post |
Parameters |
String |
'' |
List of values in the URL format passed in the HTTP request. |
Asynchronous |
Boolean |
True |
Specifies whether to make asynchronous Ajax requests. |
Postbody |
String |
Undefined |
In the case of http post, the content in the Request body is passed in. |
Requestheaders |
Array |
Undefined |
The HTTP header list that is passed in with the request. This list must contain an even number of items. Any odd number item is the name of the custom header, the following even number of items causes the string value of this header item. Example:['My-header1', 'This is the value', 'My-other-header', 'Another value'] |
Onxxxxxxxx |
Function (XMLHttpRequest) |
Undefined |
The custom method called when the corresponding event/status is formed in an Ajax request. For exampleVaR myopts = {oncomplete: showresponse, onloaded: registerloaded };This method will be passed in a parameter that carries the Ajax operation XMLHttpRequestObject. |
Onsuccess |
Function (XMLHttpRequest) |
Undefined |
The custom method called when the Ajax request is successfully completed. This method will be passed in a parameter that carries the Ajax operationXMLHttpRequestObject. |
Onfailure |
Function (XMLHttpRequest) |
Undefined |
The custom method called when the Ajax request is completed but an error occurs. This method will be passed in a parameter that carries the Ajax operationXMLHttpRequestObject. |
Insertion |
Function (object, string) |
Null |
The method to inject the returned text into an element. This method will be passed in two parameters, the object to be updated and only appliesAjax. Updater Response text. |
Evalscripts |
Boolean |
Undefined, false |
Determine whether to execute the script block when the response arrives. Ajax. UpdaterObject. |
Decay |
Number |
Undefined, 1 |
It is decided that when the last response is the same as the previous response Ajax. periodicalupdaterFor example, if the value is set to 2 and the subsequent refresh is the same as the previous result, the object will wait for the next refresh at two preset intervals, if it is the same again, it will wait four times. If you do not set this parameter, or set it to 1, the Access frequency will be reduced. |
Function getcontents ()
{
VaR request_url = "test1.html"; // URL of the content to be retrieved
VaR request_pars = ''; // Request Parameters
VaR myajax = new Ajax. Updater ('result', request_url, {// bind the content returned by request_url to the container whose ID is result.
Method: 'get', // HTTP Request Method, get or post
Parameters: request_pars, // Request Parameters
Onfailure: reporterror, // call the reporterror function when a failure occurs.
Onloading: Loading, // when the content is being obtained
Oncomplete: Done // when the content is obtained
});
}
Function loading ()
{
$ ('Loading'). style. Display = 'block ';
}
Function done ()
{
$ ('Loading'). style. Display = 'none ';
}
Function reporterror (request)
{
Alert ('sorry. There was an error .');
}
Ajax. Updater provides three States for loading documents: oncomplete, onloading, and onfailure. You can customize a function to correspond to these three states respectively.
The following example uses success (used only when everything is OK), and a failure (used when there is something wrong), which is equivalent to success. When an error occurs
OnfailureCallReporterrorMethod. <SCRIPT>
Function gethtml ()
{
VaR url = 'HTTP: // yourserver/APP/getsomehtml ';
VaR pars = 'someparameter = abc ';
VaR myajax = new Ajax. Updater (
{Success: 'holder '},
URL,
{Method: 'get', parameters: pars, onfailure: reporterror });
}
Function reporterror (request)
{
Alert ('sorry. There was an error .');
}
</SCRIPT>
<Input type = button value = gethtml onclick = "gethtml ()">
<Div id = "Placeholder"> </div>