AJAX - The Complete Reference

(avery) #1

240 Part II: Developing an Ajax Library^


var requestip = response.xhr.responseXML.getElementsByTagName("requestip")[0]
.firstChild.nodeValue;
var message = "Hello World to user from " + requestip + "!";
responseOutput.innerHTML = message;
}
else
responseOutput.innerHTML = "Cannot read packet: expected XML nodes not found";

Certainly for alternate formats like HTML, JSON, or even CSV, it is possible to come up
with a routine to look at the content to make sure it looks correct before using it. Figure 6-5
shows the Data Error Explorer (http://ajaxref.com/ch6/dataerror.html) being exercised,
which contains example code that exercises the ideas of this section.

FIGURE 6-5 Always check if a response is good data or bad data
Free download pdf