AJAX - The Complete Reference

(avery) #1

PART II


Chapter 5: Developing an Ajax Library 229


Ajax call example presented a few paragraphs earlier. If you look at it again, especially
without formatting, it looks a bit daunting:

$(document).ready(function(){$("#ratingForm").ajaxForm(function(data)
{$("#responseOutput").html(data);});});

Certainly it is quite true that jQuery can provide lots of functionality in very terse
statements, but that is also its weakness. Improper use of the library leads to an almost
LISP-like approach to JavaScript coding with tremendous function chaining.
However, the potential for abuse should not dissuade you from investigating jQuery
further. The library is quite powerful. The selector system employed by jQuery far exceeds
what we have in our AjaxTCR library, and the environment supports a very nice extensibility
mechanism. In fact there are numerous plug-ins to the environment found at http://jquery
.com/plugins, and it is quite likely by the time you read this that someone has addressed any
lack of communication facilities we mentioned. However, before concluding this section, we
really shouldn’t let jQuery fans off the hook. Any complaints people make about Prototype
changing JavaScript programming in very fundamental way holds doubly true for jQuery.
The power you are afforded really does come with a price. You may not know it now, but
when you come back in a year or two and try to read a heavily chained jQuery statement, we
hope you will remember this warning.

Other Libraries: Dojo and Beyond


Certainly this is not a complete discussion of all the Ajax libraries that exist by far. You’ll
particularly note we did not mention server-side environments that support Ajax. This is a
conscious decision on our part since Ajax really is a client-side technology. With many server-
side Ajax-focused environments spending half their effort inserting into the page a library like
the ones we saw often with less features, we wonder about the real value of such offerings.
That isn’t to say there’s not important interaction between client and server; there is, and we
will certainly discuss how client- and server-focused libraries interact in Chapter 9.
However, as we wrap this chapter up, you might ask: where library X is? Well, we
certainly can’t mention everything in a print book, but there are a few others that we would
be remiss in not mentioning. For example, Dojo (www.dojotoolkit.org/ ) is a powerful and
ever-evolving toolkit for building rich Ajax-powered JavaScript applications. It supports a
wide range of GUI elements as well as advanced Ajax-related ideas such as back button and
bookmark handling, offline storage, Comet, and likely much more by the time you read this.
Unfortunately, at least at the time of this book’s initial writing, it was poorly documented
and clearly a serious work in progress if you take some time to look at its code. Some have
also criticized how bloated the library is, though in the new releases there has been some
great effort to reduce code bloat.
Given all the interesting possibilities the library offers, we spent significant time digging
into the source code to understand some of the features, but in the end we simply had to
eliminate the material about Dojo. No conspiracy is in play other than the simple fact that
during the writing of the first edition a tremendous code change was started from the 0.4
version to a later 0.9 syntax and now a 1.0 candidate, which is completely different. We hope
that by the time this book is printed Dojo continues its trajectory and retains its new syntax,
and provides better documentation, and a more svelte coding approach. We encourage
Free download pdf