Foundations of Ajax

8 comments | Posted: 13 December 05 in Books, by Nathan Smith

Foundations of Ajax I finished reading this book a few weeks ago, but really haven’t had time to sit down and write a review that will do it justice. Yet, I’ve heard that you never find time unless you make time, so I figure now is as good an opportunity as any. First off, let me say that while I have the utmost respect for the guys over at Particletree, I’m really not attempting to just rip off their book reviews as featured in Treehouse Magazine. The reason I mention this is I wrote a book review awhile ago on DOM Scripting around the same time theirs came out.

No folks, I found this little gem of knowledge Foundations of Ajax all on my own while in Barnes & Noble drinking Starbucks coffee with my wife. I was surprised to see a title with the buzz-word Ajax already on the shelves of a mainstream bookstore. It wasn’t until later when I read the November issue of Treehouse that I realized it was also featured by them. So there, enough disclaimers and name-dropping. On with the review!

If you are looking to instantly become a master of cool Ajax wizardry, in order to employ the next bit “Web 2.0” application overnight, this book might not be for you. The authors, Ryan Asleson and Nathanial Schutta have written this book with developers in mind. From their introductory chapter:

Our motto while writing this book was, “Everything you need to know; nothing you don’t.” We assume that as a reader of this book you are already an experienced web application developer.

If that doesn’t sound like you, perhaps you should also pick up a few books on both JavaScript and a server-side programming language. This isn’t to say you won’t benefit from reading Foundations of Ajax, but you will certainly get a lot more out of it if you are already familiar with one or the other.

Much of the book revolves around usage of XMLHttpRequest. This stands for Extensible Markup Language HypterText Transfer Protocol Request, quite a mouthful! Essentially, it is the primary method of data retrieval involved in “invisible” server calls. Basically, it’s what puts the Asynchronous aspect in Ajax. Throughout, there are helpful examples of using it for form validation, as well as a few eye-candy excercises such as creating loading progress bars, typical of Flash animations as data is being buffered / cached.

What I found most interesting is that XMLHttpRequest is not actually an officially adopted standard by the W3C. Rather, it has just become so widespread that most major browsers support it in some form or another. Due to this, there is a slight bit of code forking involved when initially creating an instance of the object:

var xmlHttp;
funtion createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if {window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}

If you plan on doing any sort of Ajax work, you will likely have that bit of code above seared into your memory. The first statement checks if the browser understands ActiveX, to deal Internet Explorer’s odd behavior (big surprise). Failing that, all other browsers will treat it as a simple XMLHttpRequest. Thankfully, that’s about all the code forking that is necessary, as the rest of the computation usually takes place on the server accessing a database.

What I would liked to have seen were more “online” examples, utilizing server-side languages. This is just a personal preference though, as the book certainly delivers in all the areas it promised. For a relative newcomer to the game, I would have gotten more out of the tutorials if I’d seen how they interacted with say, PHP or Ruby on Rails. Again, this goes back to the initial assumption that the reader is an experienced web application developer.

Thankfully, the authors have developed a framework which may help you to expediate your development process. It’s called Taconite, and despite the name has nothing to do with eating Mexican cuisine in the evening. Taconite is a framework that simplifies the creation of Ajax enabled Web applications. It can be used with any server-side technology including Java Enterprise Edition and Microsoft’s .NET Framework.

The book doesn’t stop there though, and mentions a variety of other server-side technologies that could be used in web applications. Their main point of emphasis is that Ajax is not a rigid set of guidelines, but rather a flexible method of enhancing a user experience. While the ways of deploying these sites may vary, we all know when we’ve seen a site that does it well. Such examples would include Gmail, Google Maps and Netflix.

If sites like these intrigue you and quicken your pulse, then Foundations of Ajax is for you. Just remember, using Ajax is like consuming alcohol in public. It is best when done responsibly, lest you get a reputation for being an annoyance to others. Use your newfound knowledge to enhance the user experience, rather than make it unnecessarily complicated. Strive to make your websites seamlessly streamlined, and you will be using Ajax to its fullest potential.

Discuss This Topic

  1. 1 Yannick

    Thanks for the review Nathan. Sounds good. Have you been able to use any of what you have learnt in any projects yet?

    Also I was wondering how is Taconite any different from say moofx or script.aculo.us?

     
  2. 2 Nathan Smith

    Yannick: While moo.fx and script.aculo.us are visual effects libraries that can be implimented as part of the AJAX process, from what I understand Taconite helps facilitate the go-between back and forth from the browser and the server. Meaning, if Taconite is being implimented, AJAX is being used, whereas visual effects can be used with or without the asynchronous server-side aspect.

     
  3. 3 Tank

    Excellant.

    Another nice framework is Sajax

    it’s a little bloated for basic stuff, but it is very easy once you get your hands dirty a bit.

     
  4. 4 Jonathan Snook

    moo.fx and script.aculo.us are both built on Prototype—a JavaScript library. The full prototype library includes an AJAX class that would likely duplicate some, if not all, of the functionality in Taconite.

     
  5. 5 Wesley Walser

    Nice book review, doesn’t sound like one I will be picking up any time soon though.

    I don’t really know why they would go through the trouble to create their own ‘framework’ (that’s becoming another buzzword isn’t it) when they could just have said ‘here’s is how to hand code the stuff when you need to’. That, I think, would lead to more learning on the readers part. Then again they do write books a lot more often than me so whatever works for them I guess. (that little bit reminded me of the interview at the end of the new Crowder CD).

    Check out this little AJAX search of my own which I will move into the search box on richfork.com once it’s production ready.

    On a side not you talked about ‘code forking’ I think it should be said that the commonly accepted approach to AJAX is an unobtrusive one, which involves a bit more ‘code forking’ of sorts. While not really forking over completely different chunks of code to different browsers it does involved jumping through a few more hoops that straight onclick=”” links.

    You mentioned Particle Tree in the disclaimer you should also link them as a resource for people who want to learn more about Ajax and the like. Also Dustin Diaz seem to be very good at what he does, and one of the things he does it JavaScript.

     
  6. 6 Nathan Smith

    Wesley: Perhaps I did not explain fully in my review: They didn’t just create a framework and push it in their book. They also taught people how to write the code themselves, and then in their chapter on different frameworks, mentioned popular ones like Ruby on Rails, and also mentioned their own, Taconite. I see nothing wrong with that. Regarding code-forking, of course you would need to have actual checks for various levels of browser support, such as:

    if (!document.getElementsByTagName) return false;

    My main point that was as far as XMLHttpRequest is concerned, the code listed in the article is one snippet that is very commonly reused, amongst many other lines of code of course. Regarding linking to Particletree, I did already. I feel like maybe you didn’t get the gist of my article, or read through it too quickly. You’re right about one thing, Dustin is the man when it comes to JavaScript.

     
  7. 7 Wesley Walser

    Sorry about that I did in fact notice that you had linked Treehouse, but thought that perhaps Particletree had earned a second dose of linkage later own in and effort to point readers to resources.

    I read, I promise!

     
  8. 8 sharmi

    i want to know how to create a discussion forum using Ajax and ruby on rails ,will please give me any suggestions in this

     

Comments closed after 2 weeks.