Specify the callback
method with the onComplete property. The XMLHttpRequest gets
created and sent to the specified url. When the request is complete, the
showResponse function gets invoked. The function registered with the
onComplete property gets invoked with an argument containing the
XMLHttpRequest object and an argument containing the HTTP
response header.
var ajaxRequest = new Ajax.Request(
url,
{
method: 'get',
parameters: pars,
asynchronous: true,
onComplete: showResponse
});
}
function showResponse(xmlHttpRequest, responseHeader)
{//Process Http response and update input form
}
The showResponse function retrieves the XML response from the
server and updates the input form.
var xmlMessage = xmlHttpRequest.responseXML;
The input.js with JavaScript code replaced with prototype library
functions and Ajax.Request class is listed below.
function validateCatalogId(){
var catalogId=$F('catalogId');
var url = 'validateForm';
var pars ='catalogId='+catalogId;
var ajaxRequest = new Ajax.Request(
url,
{
method: 'get',
parameters: pars,
asynchronous: true,
onComplete: showResponse
});
}
function showResponse(xmlHttpRequest, responseHeader)
{
var xmlMessage = xmlHttpRequest.responseXML;
54 3 Less JavaScript with Prototype
var
valid=xmlMessage.getElementsByTagName(???valid???)[0].fir
stChild.nodeValue;
if(valid==???true???){
var validationMessage=$('validationMessage');
validationMessage.
Pages:
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69