Java Reference
In-Depth Information
Ajax event handlers are passed the following three parameters:
An
event object that has information about the event.
The
XMLHttpRequest object that is used to make the request.
An object containing the settings used for the request. With the
settings object, you can
retrieve the URL of the request, its HTTP method, whether or not the request was sent in asyn-
chronous mode, and much more.
You can build some pretty thorough error messages between the request and settings parameters.
Visit http://docs.jquery.com/Ajax for a complete list of Ajax events.
Remember the examples from the previous chapter? You created a form that checked if user names and
e-mail addresses were available using Ajax, and you sent those values to the server as parameters in the
URL. For example, when you wanted to test a user name, you used the username parameter, like this:
phpformvalidator.php?username=jmcpeak
With the $.get() method, you can do the same thing by passing an object containing the key/value
pairs to the method.
var parms = new Object();
parms.username = “jmcpeak”;
function get_callBack(data, status)
{
alert(data);
}
$.get(“phpformvalidator.php”, parms, get_callBack);
In this code, you create a new object called parms and add the username property to the object, assign-
ing it the value of jmcpeak. You then write the get_callBack() function, and afterwards, you call
$.get() and pass the URL, the parms object, and the callback function.
Sending Multiple Parameters
You can send multiple parameters to the URL by simply adding more properties to the object, like this:
var parms = new Object();
parms.username = “jwmcpeak”;
parms.email = “someone@xyz.com”;
You can send as many parameters you want or need in a single request.
By default, the $.get() method sends requests in asynchronous mode, and in most cases, this is desired.
However, you may fi nd situations, like the answer to Question 2 in Chapter 14, where you want to use
synchronous communication. You cannot specify what type of communication mode you want to use with
Search WWH ::




Custom Search