16 Part I: Core Ideas
or even some form of animated rollovers such as the ubiquitous star ratings found on many
websites.
Whatever the visual presentation and form of the communication used in the rating
system, the underlying approach will be quite similar. The user will indicate their
preference and the script will form a set of query parameters indicating the user’s rating,
what they are rating, and maybe other data items. The collected data will then be sent to
some server-side program (for example, rating.php), which will record the rating and
potentially respond or not. A complete query string might look something like
http://ajaxref.com/ch2/setrating.php?rating=3&transport=human-typed
Go ahead and type that URL into a Web browser and see what it does. You won’t see
much visually, but note that indeed the request goes through. If you look closely and
observe the data stream using a network tool, you’ll notice an unusual response type: 204
No Content.
This response code indicates that the request was successful, but nothing is returned.
Browsers will ignore the 204 response and stay at the same URL. A similar task can be
accomplished by passing back a single 1×1 pixel GIF with a standard 200 OK HTTP
response and then ignoring it if you like, but there really is no reason to do so.
On the book’s server you will find that your rating was recorded in the file ratings.txt,
which you can see at http://ajaxref.com/ch2/ratings.txt; while the total number of