How many introductions to Ajax do we need?

October 9, 2006 code 3 min read

Really, how many introductions to Ajax do we really need?

I’ve been a long time subscriber to Linux Journal but have been disappointed by the content in the past year or so. After Nicholas Petreley signed on as editor, I was encouraged to see their visual changes to the magazine (finally making it look like a magazine that could be understood by someone that doesn’t know how to write a kernel module), and I was delighted when they finally discovered Ruby this past summer. When the latest issue arrived in my mailbox, I was excited to see Tim Bray on the cover.

That excitement quickly turned into the fuel for this rant when I started paging through the issue and I came across the first article, “Beginning Ajax”. Not only do we not need another introduction to Ajax, why are we still writing introductions that use the low level XmlHttpRequest object and explaining to our readers how you have to use ActiveX on IE?

I use Ajax in some form on most of the apps that I write, but beyond the examples from the first introduction to Ajax article that I read, I have NEVER used the low level JavaScript calls for doing Ajax. Prototype eliminates the need to use the low level handling of Ajax:

new Ajax.Updater('div_to_update', '/dosomething', {
    onComplete: doSomething(request),
    onLoading: showSpinner();

That’s a heck of a lot cleaner than the 25 line example in the Linux Journal article. xhr.readyState == 4, who cares?

What’s even more interesting, using Rails, I rarely even write code using Prototype. More commonly, I write:

<%= link_to_remote('edit',
  :update => 'div_to_update',
  :url => {:action => 'edit', :id => object})

90% of the time, this is more than sufficient, and for that other 10%, I am intimately familiar with Prototype and can accomplish the same thing in a fraction of the time that it takes to write the raw JavaScript.

So, again, I ask, why are we still writing introduction to Ajax articles that use low level JavaScript? I agree that it is important to understand how Ajax works, but there are plenty of articles that do that. No one (in their right mind) would actually use this code in their production apps.

This content is open source. Suggest Improvements.


avatar of Brandon Keepers I am Brandon Keepers, and I work at GitHub on making Open Source more approachable, effective, and ubiquitous. I tend to think like an engineer, work like an artist, dream like an astronaut, love like a human, and sleep like a baby.