OPINION

Easy Ajax: A Case Study

Written by Phillip Winn
Published December 30, 2005

Developing web applications using "Ajax", or Asynchronous Javascript And XML, is easy. So easy that it is easy to overlook "gotchas" and make major mistakes, or to try to use Ajax in situations for which it is inappropriate. This article outlines a successful use of Ajax to add concurrency control to a blogging system, and the issues I encountered during development.

When To Use Ajax

AJAX is a web development technique for creating interactive web applications. Ajax applications are mostly executed on the user's computer; they can perform a number of tasks without their performance being limited by the network. This permits the development of interactive applications, in particular reactive and rich graphic user interfaces. Jesse James Garrett of Adaptive Path is generally credited with popularizing the term "Ajax" as a result of his seminal essay on the technology.That article introduces the concepts and establishes that the Ajax approach can work well, but it does tend to leave people with the impression that Ajax can solve every problem, and that just isn't the case.

The biggest problem with applications that use Ajax is that the URL never changes. In Google Maps, for example, there is a "Link to this page" function to get around this problem. It takes careful planning to know when to use Ajax and when to just link to a new URL.

How To Use Ajax

The problem facing me happened to involve a heavily-customized version of a popular blogging system, but only three very minor bits actually have anything to do with that. More importantly, I needed to implement a concurrency control system so that multiple editors couldn't edit the same article and overwrite changes from each other.

In this case study, I want to ensure that only one person at a time has the right to edit a given article. I could issue a database call at page-load to see if anybody else has it locked, or to lock it myself, but how would I know when a user is done editing the page? If the user navigates away from the page, how can I let the database know? I can't refresh the entire page at a regular interval, because editing changes would be lost. I need to be able to constantly let the server know that the user is still actively editing an article, and when that regular update stops, then I'll know that the user has moved on. The only URL will be an internal URL which never needs to be bookmarked, so there are no worries there!

page 1 | 2 | 3 | 4 | 5
Phillip Winn is the Chief Geek for BC Magazine, and a blogger since 1995. He may currently be found and followed on Twitter.
Keep reading for information and comments on this article, and add some feedback of your own!
Easy Ajax: A Case Study
Published: December 30, 2005
Type: Opinion
Section: Sci/Tech
Filed Under: Sci/Tech: Internet
Writer: Phillip Winn
Phillip Winn's BC Writer page
Phillip Winn's personal site
Spread the Word
Like this article?
Email this
Submit to del.icio.us Save to del.icio.us
RSS Feeds
All RSS Feeds (240+)
Comments on this article
BC articles by Phillip Winn
Sci/Tech: Internet
All Sci/Tech Articles
Phillip Winn's personal weblog
All Opinion articles
All BC articles
All BC Comments

Comments

#1 — December 31, 2005 @ 00:28AM — Aaman [URL]

I wish that Ajax book was cheaper:)

Incidentally, is this true AJAX, does the reliance on PHP and SQL not mean a new paradigm, not reliant on XML?

#2 — December 31, 2005 @ 11:49AM — Phillip Winn [URL]

It's still XMLHttpRequest, so all three elements of AJAX are present. The PHP and Mysql are, I think, incidental. It could as easily be anything else, or an external webservice, on the "back end."

Want comments emailed to you? No spam, promise! Address:

Add your comment, speak your mind

(Or ping: http://blogcritics.org/mt/tb/41621)

Personal attacks are not allowed. Please read our comment policy.





Remember Name/URL?

Please preview your comment!

Fresh
Articles
Fresh
Comments