What you need to grok to grok Ajax

Dojo’s Alex Russel has a good post on the fundamentals of JavaScript here. There is a big difference between being able to get by in JavaScript and being able to really work with it.

As far as Ajax goes, in addition to understanding the ins and outs of Javascript, I’d say that there’s a great benefit to understanding HTTP properly. Within the confines of a classic web app, all the low-level HTTP stuff is handled for you, but XHR gives you much more flexibility. I’ve blogged on some aspects of this before before. Here are a few more quick tips:

  • HTTP doesn’t mandate key-value pairs for request data, that’s just a convention built on top of the protocol. You can construct XML documents and pass them in as a POST body, for example. Most server-side technologies will let you read the raw content body directly
  • if you do want the server-side to automatically parse your content as key value pairs, make sure you set the request header to application/x-www-form-urlencoded
  • there are more HTTP verbs than POST and GET. HEAD, for example, allows you to find out about a resource without the overhead of downloading it.

As with most things techy, I like to learn by doing. There are plenty of good tools for debugging HTTP, my current favourites being Fiddler and the Apache TCPMonitor.

Comments are closed.