The Ajax.Request Library Class
The zipChanged function uses the Ajax.Request class from the
prototype library:
function zipChanged(zip) {
if(zip.length != 5) {
clearCityAndStateFields();
}
else {
new Ajax.Request(
"zipChanged.ajax", // URL
{ method: "get", // HTTP method
parameters: "zip=" + zip, // Request params
onComplete: processZipCodeSelection, // callback
});
}
}
- If the length of the zip code string is not 5, the city and state fields
are cleared
- The third argument to the constructor, of the form { . . . }, is a
small hash table
- The server needs the submitted zip to check, so it is sent in a request
parameter
- When the response is complete, the callback
function processZipCodeSelection is invoked on the client