Call (877) SITE-OPT (748-3678)

Figure 8-7. OK-it's an error!

Chapter 8 - Ajax Optimization

There are more than just network errors to be concerned with in Ajax applications. Just waiting around to get a 200 OK HTTP response isnít going to ensure that you actually have the content you were expecting. Application servers far too often return error messages with such indications, and if you use the basic code such as this:

function responseCallback(xhr)
    if (xhr.readyState == 4 && xhr.status == 200)
        /* go to work */

it isnít going to keep you from outputting or consuming an error message as though it were content (see Figure 8-7).

spinning progress bar

Figure 8-7. OKóitís an error!

Your only protection against server and content errors is careful inspection of each and every response. If you donít see what you expect, bail out.

Copyright © 2002-2018 Website Optimization, LLC. All Rights Reserved - Free website speed test - Privacy Policy
Last modified: February 19, 2009.

Follow us on: Twitter, Google+, Facebook, Linked In