Archive: February 27th, 2005

S'more DOM Scripting

Speaking of cool JavaScript applications

Dave Shea has redesigned his Bright Creative website and he’s using my slideshow script for his design portfolio. I’m glad to see that it scales up to having multiple slideshows on one page.

And now it’s time for me to eat humble pie. Google Maps, contrary to my expectations, is clearly being developed continuously. It is now working flawlessly in Safari.

Note, for example, this page of directions from the hotel where I’ll be staying during South by SouthWest to the venue where Kings of Leon will be playing that week.

Applied Ajax

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.