The Example Given

Throughout this Short Cut, we use the same example to illustrate Ajax concepts. This approach best demonstrates the various ways of accomplishing the same task while staying with an example you may find familiar.

Our applications allow the user to type in a full or partial title or author of a book and then present information about any matching books and Short Cuts.

The use case for the example is as follows:

  1. User visits the page and is presented with a form that has the fields "Title" and "Author."

  2. User types in the partial title of the book and/or the partial author name.

  3. The user presses "Search."

  4. The result div (box) is filled with the text "Performing search... please wait."

  5. The server is queried using an XMLHTTPRequest object for the appropriate books.

  6. The server returns the results using a specified data format (XML or JSON).

  7. The results are displayed to the user.

Throughout this Short Cut the result will stay the same but the methods used to obtain that result will gradually become more sophisticated.

The CSV File

Because this Short Cut covers Ajax and PHP only, we won't discuss database access and searching algorithms. Instead, we use a simple Comma Separated Values (CSV) file to store the books (and Short Cuts!) for which we will be searching and a basic class to load and search the file.

This CSV file and class is used in every subsequent example. You can, of course, modify the class to search in a more expansive database—be creative. First copy this data into ...

Get Ajax with PHP 5 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.