AJAX - The Complete Reference

(avery) #1

36 Part I: Core Ideas


Encoding Data in Image Dimensions
The previous example showed the most obvious use of two-way images, making new
images dynamically, but how might you deal with receiving nonimage data back from the
server? Well, one limited way to do this is to encode some meaning in the dimensions of an
image. Such an approach is illustrated by use of an example, an uptime checker (http://
ajaxref.com/ch2/connectioncheck.html). In this demonstration, the server-side program
called connectioncheck.php will generate an invisible image encoded with data. The
image height indicates the uptime status (up being 2 and down 1) and the width indicating
the rough roundtrip time in milliseconds. Upon receipt of the image, the height and width
are inspected and the appropriate message is displayed to the user.

FIGURE 2-5 Custom-generated image example
Free download pdf