Copyright © tutorialspoint.com
This AJAX method initiates and processes an AJAX request. This object is a general-purpose AJAX requester: it handles the life-cycle of the request, handles the boilerplate, and lets you plug in callback functions for your custom needs.
In the optional options hash, you can use any callback function like onComplete and/or onSuccess depending on your custom needs.
new Ajax.Request(url[, options]); |
As soon as the object is created, it initiates the request, then goes on processing it throughout its life-cyle. The defined life-cycle is as follows:
There is set of callback functions, defined in Ajax Options, which are triggered in the following order:
Depending on how your browser implements XMLHttpRequest, one or more callbacks may never be invoked. In particular, onLoaded and onInteractive are not a 100% safe bet so far. However, the global onCreate, onUninitialized and the two final steps are very much guaranteed.
You can pull the brake on a running PeriodicalUpdater by simply calling its stop method. If you wish to re-enable it later, just call its start method. Both take no argument.
<html> <head> <title>Prototype examples</title> <script type="text/javascript" src="/javascript/prototype.js"> </script> <script> function SubmitRequest() { new Ajax.Request('/cgi-bin/ajax.cgi', { method: 'get', onSuccess: successFunc, onFailure: failureFunc }); } function successFunc(response){ if (200 == response.status){ alert("Call is success"); } var container = $('notice'); var content = response.responseText; container.update(content); } function failureFunc(response){ alert("Call is failed" ); } </script> </head> <body> <p>Click submit button see how current notice changes.</p> <br /> <div id="notice">Current Notice</div> <br /> <br /> <input type="button" value="Submit" onclick="SubmitRequest();"/> </body> </html> |
Here is the content of ajax.cgi
#!/usr/bin/perl print "Content-type: text/html\n\n"; print "This content is returned by AJAX cgi <br />"; print "Current Time " . localtime; |
To understand it in better way you can Try it yourself.
You can pass the parameters for the request as the parameters property in options:
new Ajax.Request('/some_url', { method: 'get', parameters: {company: 'example', limit: 12} }); |