AJAX - The Complete Reference

(avery) #1

478 Part II: Developing an Ajax Library^


The key items to note are the line at the top that includes the JavaScript library and the
bit of code which makes the link tag Ajaxified. If you run this in a browser and look at the
code you will see something like this:

What we just saw looks quite familiar if you remember our discussion of the wrapped
widget. The same thing is going on here. JavaScript code is being inserted, in this case, based
upon Ruby statements. If you go and look at other tightly coupled systems, you will see the
same approach but, in some cases, special tags will be used instead. In some situations, such
as the Google Web Toolkit (http://code.google.com/webtoolkit), we see the same approach
but even more than remapping, GWT will literally compile Java code to JavaScript.
Whether it is an IDE generating the code like ASP.NET, a special magic statement you
run like Rails, a function call to make the JavaScript go in, language translation from what
you like to JavaScript or some newfangled tag abstracting the details away, underneath it all
is our friend JavaScript and likely lots of it. JavaScript using XHRs, filled with closures and
chock-full of all sorts of interesting challenges both annoying and inspiring.
So why do we pretend so hard that JavaScript isn’t there? Some people are ignorant of
JavaScript, some just don’t like it, and some do, but whatever your feeling is about it, the
fact is that it isn’t going anywhere. JavaScript is what is driving Ajax, like it or not. So why
abdicate your ability to make Ajax fly? Instead we encourage you to dive in.
Free download pdf