Bulletproof Ajax
I wrote this post a while back. The content can still be relevant but the information I've linked to may not be available.
- Author: Jeremy Keith
- Paperback: 216 pages
- Publisher: New Riders (March 2007)
- ISBN-10: 0321472667
- Amazon UK Typical price: £16.49
In more detail
The book is aimed at the front-end developer who uses semantic mark-up and CSS every day. If you are a JavaScript expert or hardcore coder, this is probably not the book for you. If you enjoyed DOM Scripting, the book is well worth it.
The book is well-structured and it starts with an explanation of Ajax. In simple terms, updating one part of the webpage after a user action - without a complete page reload. This is followed by a recap of basic JavaScript methods [very useful for a clunkhead like me].
» Related: The original Ajax article and Ajax in Wikipedia
Subsequently, there is a detailed explanation of the XMLHttpRequest object, which is the 'heart and soul of Ajax' for communicating between browser and server in Ajax applications, and a bulletproof method for creating an instance of the object with its request is described. Finally in this chapter, processing the server response is described with a simple example. Speaking as someone who often comes into these things as the result of a customer request, it's great to have a rock-solid basis as the starting point for any new methodology.
This section contains really useful summaries of the pros and cons of each format
The next chapter discusses the data returned from the server after the Ajax request and describes the three data formats that are commonly used, XML, JSON and HTML (using the innerHTML property), with examples. This section contains really useful summaries of the pros and cons of each format. The rather long-winded creation of page content from XML or JSON data was eye-opening. There's a lot of JavaScript 'work' involved and I imagine this could rapidly escalate in larger applications.
The innerHTML property is used for the rest of the book. This definitely makes the book easier to understand but I would have liked other examples. In particular, the use of JSON which I have seen advocated by people on a few occasions recently.
The use of innerHTML is possibly a bit surprising considering that it is a proprietary method [so is the XMLHttpRequest object]. On the other hand, this is clearly a better way of processing the response in some cases.
Hijax it up!
This is the basis for the Hijax method and it is clearly explained
By intercepting user input and sending the request with the XMLHttpRequest object, JavaScript can be used to enhance functionality. At the same time, the application is built as a regular webpage and it still works if JavaScript is disabled. This is the basis for the Hijax method and it is clearly explained here. There are several good examples including contact form input processing with error messages that are displayed in Ajax fashion.
Ajax challenges
The next two chapters discuss the potential problems of Ajax methodology including backwards compatibility, bookmarking, the back button, how to provide user feedback when an Ajax request is underway [nice examples], and in particular, the accessibility of Ajax applications. I am not sure that there is a clear answer to the accessibility issue but the book does not sidestep this potential problem.
The final 'code' chapter builds on methods from previous chapters to construct a one-page shop called Bulletproof Books. Perhaps inevitably, this is a simple example but it pulls together a number of Ajax methods. Even allowing for the fact that it is quite simple, I found this a bit of a 'step-up' in understanding. It's a section that I need to re-read a few times. Additionally, I need to look at the code examples from the book in more detail.
Looking ahead
The final section of the book discusses the future of Ajax and the usage of JavaScript libraries. The author urges caution with the use of libraries if you do not understand them. I agree but time is sometimes the limiting factor. Personally, I have found that the jQuery library has saved me a lot of time in a few projects and I don't know how I would have achieved the same effects in the timescale required without it. In these cases, I wouldn't say that I spent a lot of time understanding every single aspect of how jQuery works either. Sorry 'bout that!
A final quote from the last section "it makes sense to keep Ajax enhancements lightweight and subtle". And as bulletproof as you can make them, surely!
Summary
This book is a great introduction to Ajax methodology. It is clearly written and provides a solid basis for understanding Ajax. If you want to start adding Ajax enhancements to your website, read this book!
» Buy it from Amazon UK
Previously on this blog: Reviews of Bulletproof Web Design and DOM Scripting
Comments
12 Apr 2007 09:59:21
Nice use of microformats Clive.
12 Apr 2007 11:00:31
Thanks Simon. Yes, I am trying to use them more and more. It does take more work but in this case I have a specific Textpattern ‘hReview form’ that I use which makes it easier.
Comments are OFF for this post.