AJAX - The Complete Reference

(avery) #1

58 Part I: Core Ideas


interface widgets as well. Interestingly, if you inspect most Ajax libraries online you’ll see
that they tend to be better UI libraries than communication libraries. However, the author
wonders that while end users may very much appreciate a nice UI, how forgiving will they
be if it fails less than gracefully because it is not robust at the network level?

RSS Reader

As another two-way example we present an RSS reader using the script tag at http://
ajaxref.com/ch2/rssreader.html. Its use and communication trace is shown in Figure 2-12.
When you inspect its code you’ll notice a few things. First, the code does not actually talk to
the URL you specify directly. Instead, it calls rssreader.php, which goes and fetches the user-
specified URL. You will find this proxy style approach is required even when you use Ajax
techniques because of security limitations. Second, you’ll note by looking at Figure 2-12 or
inspecting the data transmission that a raw RSS file in XML format is not passed back from
the server but instead the relevant part of the feed converted into JSON format is sent for
quick painting by the client-side JavaScript. The data choice for communication will be an
ongoing decision not to be taken lightly, as a wrong choice will significantly bloat your code
and may slow your application.

FIGURE 2-11 Aesthetically improved ratings
Free download pdf