Ajax for beginners

As mentioned yesterday I have been reading “Ajax: A Beginner’s Guide” by Steven Holzner. I finished it today and must say: an excellent read and absolutely worth the time spent on it ! It teaches the fundamentals around HTML, XML, dynamic HTML, Javascript and PHP in the context of developing dynamic web applications with what is called Ajax technology. It comes with 12 easy to digest chapters and lots of examples to go through and try on your own. In order to do the latter for almost all examples of course a web server is needed and PHP for the examples making use of PHP as a very common means to do  server side programming. Since I have Apache 2.2 set up on my thinkpad and PHP installed I have been able to do all these examples and really learn all the nice things you can do we Ajax.

A lot of the fundamentals have not been really new to me but it actually did not hurt to go through this again and add some more solid knowledge around a few topics and some great tips by the author like

  • the difference between GET and POST and how to handle that
  • usage of an anonymous inner function as the easiest way to handle multiple XMLHttpRequest objects
  • usage of array type names for form elements to handle many forms and containing elements through arrays
  • usage of literals as an index for arrays in PHP
  • handling timeouts
  • handling image maps
  • the real difference between client side and server side programming

The latter became real obvious when debugging my examples. Based on the fact that in Books24x7 apparently scanned-in soft copies of the original books are used a lot of typos made it into the code in form of incomplete lines and thus missing semicolons or brackets, or additional blanks, or the typical confusion between e.g. “1” ( the number ) and “l” ( the letter ). It turned out that HTML and Javascript errors are easy to catch through the browsers error console ( because that’s of course code running on the client side ) while PHP errors are invisible on the browser and one has to peek into the server side log files to catch those. Makes sense, but experiencing it is a different thing.

As I mentioned browser: what I really like as well about the book is that the author puts a lot of focus on the differences of browser and what works and what doesn’t work in either Microsoft’s Internet Explorer (IE) or Mozilla based browser. Capturing mouse events for instance works very different in IE vs. Firefox and the author shows an elegant way to write a wrapper function to deal with both cases. There are four different dynamic HTML properties available, but only one works in Firefox: innerHTML. And most annoying is the way Mozilla based browser create a DOM ( the Document Object Model ) from a web page compared to IE: for some strange reason the DOM created by a browser like Firefox contains blank elements for the indents in front of nested tags. Hard to explain, but this is a great way to confuse programmers and make properties like firstChild or nextSibling hard to use. Again a nice way is shown how to detect whether a Mozilla based browser is used and to remove those dummy “white space node"s” in this case. Well done ! The author also highlights what works in both browsers and thus gives great advices what to consider when you want to develop some web applications supposed to work in both types of browser.

So, if you consider to do some Ajax web development, this is a must read ! 12 Chapters – if you do 1 per day you are done in two weeks. It takes may be 1 or 2 hours per chapter including trying out the examples. Well invested time, to my mind !


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: