HTML and CSS Reference
In-Depth Information
EXAMPLE (S AMPLE C ODE )
//Callback function
ajaxRequest.onreadystatechange = function() {
var textObj;
textObj=document.getElementById("message");
if(ajaxRequest.readyState == 4){
//alert(ajaxRequest.status);
if(ajaxRequest.status==200){
textObj.innerHTML=ajaxRequest.responseText ; /* Get text
in a string returned by the server. */
}
}
else if(ajaxRequest.status == 404){ //Bad URL
textObj.innerHTML="Resource unavailable";
}
else{
alert("Error:" +
ajaxRequest.statusText);
}
}
The responseXML property. The 'x' in Ajax stands for XML, and although you
don't have to use XML to create Ajax applications, data from more complex and struc-
tured XML documents can be returned by an HTTP request and assigned to the object's
responseXML property. This property contains an XML document object, which can be
examined and parsed using the DOM, in the same way we used the DOM in Chapter 15,
“The W3C DOM and JavaScript.” The following example demonstrates how to create a
simple XML file and how to use Ajax to retrieve the file data and use the DOM to access
the information (see Figure 18.5).
EXAMPLE (S AMPLE C ODE )
var xml = ajaxRequest.responseXML; //Get an XML object
alert(xml);
Figure 18.5 The Ajax responseXML property contains an XML document object.
 
Search WWH ::




Custom Search