AJAX - The Complete Reference

(avery) #1

238 Part II: Developing an Ajax Library^


on200 : show200,
onFail : showFail,
on404 : show404,
on500 : showServiceDown
};

Figure 6-3 shows some screens from the example found at http://ajaxref.com/ch6/
servererrorexplorer.html. This example allows you to trigger a number of errors to exercise
the handling methods and also includes retries and timeouts for completeness.

Handling Content Errors


Even if a server is up and responds with a 200 status code, that doesn’t necessarily mean
that the response was correct. For example, many server-side environments will issue a
“200 OK” status when a server-side script error is generated. There is little indication that
this has happened by simply looking at the status code of the response and many scripts
will use the data in the response without considering anything to be wrong. Skeptical
readers might want to look at the captures in Figure 6-4 or visit http://ajaxref.com/ch6/
contenterrors.html to see this problem in action.

NNOT EOTE Do not assume that because the server-side program is written in PHP that the issuance of
a 200 status code for an error is some oversight found solely in the PHP environment. This
concern is common to just about any server-side framework environment.

FIGURE 6-3 Catch ser ver errors if you can
Free download pdf