Finally, I no longer have to use the tongue-twisting phrase XMLHttpRequest every time I want to talk about a web app that uses JavaScript to make calls to a web server. Jesse James Garrett has coined the term Ajax: Asynchronous JavaScript and XML.
I like it. It’s certainly a lot easier to say than ex emm ell aitch tee tee pee request. I also like the idea of a web technology that shares its name with a Greek warrior from the Trojan war (even if the name also conjures up images of cleaning products).
I’ve just introduced a bunch of Ajax enhancements over at The Session. If you go to any of the main site sections (the tunes section, for instance), there are tabs for the newest tunes, the newest comments and a search form. You can navigate through these lists with previous/next links as well as page numbers. I’ve used JavaScript to intercept these links and then conjure up the Ajax magic.
Here’s the source code. When one of those links is intercepted, the current content is deleted and replaced with a loading image. Then the XMLHttpRequest does all the work and gets the next set of results. Those then get inserted into the page.
There are couple of teeth-grinding moments where I have to fork the code but overall it’s pretty straightforward. The end result works quite nicely. It’s a snappy way of moving through multi-page lists without requiring a page refresh.
If you don’t have JavaScript enabled, everything continues to work with old-fashioned server-side magic. It works quite nicely in Lynx.
This Ajax is pretty powerful stuff. Web developers just need to realise that with great power, yada, yada, yada, responsibility.