The Internet's only wheelchair-accessible website.
blog
Ajax to the max
(March 23rd, 2006 - 3:00PM)
I've decided I like Ajax, and here's why: it's a JavaScript methodology that lets you minimize your use of JavaScript. (For those of you unfamiliar with Ajax, read Jesse James Garrett's article, "Ajax: A New Approach to Web Applications.")
I'm not going to pull any punches here: I hate JavaScript. It's a lousy technology that's difficult to work with and difficult to get right. Applications with large portions of JavaScript tend to bloat out of control and become difficult to maintain. Unfortunately, there are some tasks that are best done through JavaScript, so it's difficult to avoid it. Until now.
Ajax (or Asynchronous JavaScript + XML) allows you to render specific areas of your page on the fly with server-side content. I won't explain in more details, because articles such as Jesse James' describe Ajax far better than I ever could. Essentially, the idea is this: when you click a button or some other event occurs, instead of executing a huge pile of JavaScript, the user's browser simply executes a small snippet of JavaScript that sends a request to a server and displays the response. Although it's possible for the JavaScript to do fancy rendering on the server's output, it's not necessary. You can very easily just download content from the server and display it exactly as-is.
Ajax simplifies a lot of common Web development problems. For example, have you ever attempted to validate user input on a Web form? A common solution is to implement a browser-level check in JavaScript. However, you also have to implement the same validation routines on the server, just in case the user has JavaScript disabled or is maliciously trying to bypass your controls. This means you've got the same logic in two places, which is error-prone and time-consuming. However, with Ajax you only need to implement your validation routine on the server. The JavaScript can simply call the server's routine and display the results to the user instead of trying to validate input itself.
Although the purpose of Ajax is not to minimize use of JavaScript, it certainly makes doing so easier. That's why I like it. No longer are you required to develop tons of software in some unsophisticated, weakly-typed language that is always open source and behaves inconsistently on different browsers. You just need to write enough JavaScript to download and display output from a server. And you can do so asynchronously, which means that the user's browser won't freeze while waiting for a response.
For an example of Ajax in action, see My experiment with Ajax. The "show comments" link calls a simple Ajax routine that asynchronously downloads comments from my server and displays them when the results are retrieved. I actually implemented some display-generating JavaScript instead of just displaying the server output as-is, but I could have very easily implemented this on the server instead, thus reducing the amount of JavaScript needed. View the JavaScript source if you're interested.
permanent link - digg this post - 0 comments0 comments


