Java Reference
In-Depth Information
using ajax support
Unfortunately, Prototype's Ajax support isn't as straightforward as jQuery's. Prototype's Ajax
functionality centers on its
Ajax
object, which contains a variety of methods you can use to make
Ajax calls. This object is much like the
jQuery
object in that you do not create an instance of
Ajax
;
you use the methods made available by the object itself.
At the heart of the
Ajax
object is the
Ajax.Request()
constructor. It accepts two arguments: the
URL and an object containing a set of options that the
Ajax
object uses when making a request. The
options
object can contain a variety of option properties to alter the behavior of
Ajax.Request()
.
The following table describes just a few of them.
option
desCription
Determines whether or not the
XMLHttpRequest
object makes the request in
asynchronous mode. The default is
true
.
asynchronous
The HTTP method used for the request. The default is
"post"
.
"get"
is another
valid value.
method
A callback function invoked when the request completes successfully
onSuccess
A callback function invoked when the request completes, but results in an error
status code
onFailure
Either a string containing the parameters to send with the request, or an object
containing the parameters and their values
parameters
Note
For a complete list of options, visit the Prototype documentation at
Making a request with Prototype looks something like the following code:
function requestSuccess(transport) {
alert(transport.responseText);
}
function requestFailed(transport) {
alert("An error occurred! HTTP status code is " + transport.status);
}
var options = {
method: "get",
onSuccess: requestSuccess,
onFailure: requestFailed
};
new Ajax.Request("someTextFile.txt", options);