Java Reference
In-Depth Information
As the callback event handler is
processRequest
, the
processRequest()
function gets invoked when the value of the
readyState
property changes. In the
processRequest()
function, the
readyState
property value is retrieved. If the
request has loaded completely, corresponding to
readyState
value
4
, and HTTP
status is "OK", we invoke a JavaScript function to process the response from
the server:
function processRequest(){
if(xmlHttpRequest.readyState==4){
if(xmlHttpRequest.status==200){
processResponse();
}
}
}
Processing the server response
In the
processRequest()
JavaScript function, if the HTTP request has loaded
completely, which corresponds to
readyState
property value
4
, and the
HTTP status is "OK", which corresponds to
status
property value
200
, the
processResponse()
JavaScript function gets invoked. In the
processResponse()
function, obtain the value of the
responseXML
property. This contains the XML
string that was set in the
doGet()
method of
EJB3ClientServlet
.
var xmlMessage=xmlHttpRequest.responseXML;
The
responseXML
property contains instructions in XML form about the validity of
the
CatalogId
value specified in the input form. Obtain the value of the
<valid/>
element using the
getElementsByTagName(string)
method:
var valid=xmlMessage.getElementsByTagName("valid")[0].firstChild.
nodeValue;
If the
<valid/>
element is set to
true
, set the HTML
validationMessage
div to
"Catalog Id is Valid", and enable the
Submit
button in the input form, as shown below:
if(valid=="true"){
var validationMessage=document.getElementById("validationMessage");
validationMessage.innerHTML = "Catalog Id is Valid";
document.getElementById("submitForm").disabled = false;
}
Search WWH ::
Custom Search