Sign In/My Account | View Cart  
advertisement




Listen Print Discuss

Using Ajax from Perl

by Dominic Mitchell
March 02, 2006

Add Tag Clouds to Your Site

If you're even remotely connected to web development, you can't have failed to have heard of Ajax at some point in the last year. It probably sounded like the latest buzzword and was one of those things you stuck on the "must read up on later" pile. While it's definitely a buzzword, it's also quite a useful one.

Ajax stands for "Asynchronous JavaScript and XML." It's a term coined by Jesse James Garret in "Ajax: A New Approach to Web Applications." Ignore the football team, they're mere impostors. ;-)

What does that actually mean? In short, it's about making your web pages more interactive. At the core, Ajax techniques let you update parts of your web page without reloading the whole page from scratch. This enables some very cool effects. Many people cite Google Maps and Gmail as great examples of what you can do with this, but my favorite bit of Ajax is part of Flickr.

When you log in to Flickr, you can see the photos that you have just uploaded. In this example, it's something I've snapped from my camera while out cycling. Unfortunately, the phone has given it a default filename, which is quite uninformative (Figure 1).

The original photo in Flickr
Figure 1. The original photo in Flickr

If you click on the title, it turns into a highlighted text box (Figure 2).

Editing the photo title
Figure 2. Editing the photo title

After changing it to something more suitable, hit the Save button and the screen briefly tells you what it's doing, before returning to its original form (Figure 3).

Finished editing the photo title
Figure 3. Finished editing the photo title

Behind the scenes, Flickr uses JavaScript to make a separate call back to the server to update the details. It does so by using something called XMLHttpRequest. You'll hear a lot about this as you explore Ajax.

Flickr lets you edit most of the details of your photo without having to go to a separate edit page. It's a very simple enhancement, but one that makes the whole application much easier to use. It's well worth getting to know these sorts of techniques in order to spice up your own applications. It's also worth pointing out that they are enhancements. If you have JavaScript turned off, Flickr will still let you edit the photo details. You just have to use a separate edit screen and a round trip to the server. Using Ajax lets you streamline your users' experience.

What about all this messy JavaScript? Didn't we get rid of all that a few years ago? Well, yes. The kind of JavaScript that looks like Perl Golf is long gone, and good riddance. I'm sure you feel the same way about those Perl 4 scripts you wrote a few years back, before you discovered how modules work in Perl 5. Modern JavaScript is a different beast. It's relatively standard, so the cross-browser problems of the past are gone or greatly diminished. There's also a renewed focus on making JavaScript as unobtrusive as possible. With all of this change, there's even an attempt to rebrand JavaScript in the browser as DOM scripting.

There are several bits to Ajax:

  • Asynchronous: Making sure that any activity doesn't lock up the browser while it happens.
  • JavaScript: For manipulating the page inside of the web browser.
  • XML: For returning data from the server.
Building Tag Clouds in Perl and PHP

Essential Reading

Building Tag Clouds in Perl and PHP
By Jim Bumgardner

Tag clouds are everywhere on the web these days. First popularized by the web sites Flickr, Technorati, and del.icio.us, these amorphous clumps of words now appear on a slew of web sites as visual evidence of their membership in the elite corps of "Web 2.0." This PDF analyzes what is and isn't a tag cloud, offers design tips for using them effectively, and then goes on to show how to collect tags and display them in the tag cloud format. Scripts are provided in Perl and PHP.

Yes, some have said tag clouds are a fad. But as you will see, tag clouds, when used properly, have real merits. More importantly, the skills you learn in making your own tag clouds enable you to make other interesting kinds of interfaces that will outlast the mercurial fads of this year or the next.


Read Online--Safari
Search this book on Safari:
 

Code Fragments only

Pages: 1, 2, 3, 4

Next Pagearrow