11.1. History

AJAX itself is not new; nor is the idea behind it. In fact, many methods have been developed and used in the past to communicate with the server without a page refresh.

11.1.1. The Image Source Trick

JavaScript allows dynamic loading of images using the Image object. When one creates an image and sets its src property, the browser sends a request for the image and attempts to package the response in the image object. Developers have used this to make one-way communication with a server by setting the src attribute to the URI of a server-side script, passing data to the server in the query string. The server-side script might then update a data store. Typically, no image is returned in the response, but this does not cause problems, as the developer does not use the Image object for its intended purpose.

The positives of this technique are:

  • It allows for sending of data to the server without refresh.

  • It can read properties of the object to determine when request is complete.

However, it does have some drawbacks:

  • It cannot receive non-graphical data from the server (communication is one-way).

  • It cannot detect nor handle HTTP errors that may have occurred during the attempted communication.

11.1.2. Hidden Frames

Many developers found the Image source trick to be inadequate and required the ability to receive information from the server in addition to sending to it. Enter the use of a hidden frame. In this technique, the developer uses a frame with no visibility (by ...

Get Professional LAMP: Linux®, Apache, MySQL®, and PHP5 Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.