Monday, November 26, 2007

What is AJAX?

I have been among the interviewers at my work places for 50+ technical interviews, at different stages, for different positions, ranging from positions requiring fresh graduates to 4-5 years experienced resources. Out of all those interviews, I can count those good ones on fingers who correctly answered “What is AJAX?” So I consider it a worth sharing information, “What actually AJAX is”.

If you have any of the below questions in your mind, then I would recommend you to continue reading this post.
  • Is it a tool?
  • Is it a language?
  • Is it a technology?
  • Is it a library?
  • Is it a technique?
  • What’s so special about AJAX?
  • What’s working behind the scenes in AJAX?
  • Can’t we do the same trick if we don’t have the XMLHttpRequest object available in browsers?
  • Can’t we make an AJAX request synchronous?
  • How comes AJAX improve the responsiveness of a Web Application?
  • Is the round-trip eliminated in case of AJAX?
  • When to use AJAX?

Here are the points one needs to remember about AJAX, so as to have a clear understanding of what it actually is, what’s working behind the scenes, what are it’s alternates, when to use it and when not to use it.

  • “AJAX stands for Asynchronous JavaScript and XML”.
  • “AJAX is a technique” to make web applications more responsive, by enabling the application developers to “seamlessly make a request to the server without the need to Post Back the complete page” in order to provider better user experience.
  • AJAX is a “mix of JavaScript, HTML, CSS, DOM, XML/JSON”
  • The core object that’s working behind the scenes to seamlessly make a request to the server and is available in all modern browsers is “XMLHttpRequest / Microsoft.XMLHTTP”.
  • There are “many libraries/frameworks written on top of this XMLHttpRequest / Microsoft.XMLHTTP” object that facilitate the AJAX based development. ASP.NET AJAX is one of those 100s of frameworks available for free to the ASP.NET developers to incorporate AJAX features in their ASP.NET based web applications.
  • “We can make a synchronous requests” with XMLHttpRequest too.
  • “We can do a similar trick as of AJAX by using the old & gold HTML Frames (a 0 sized frame)” and use Java Script to change the “src” attribute of that 0 sized frame based on some user action, to make a seamless request to the server, without the need to post back the actual page shown in the frame actually visible to the end use, and once the requested page in 0 sized frame is loaded, you can use JavaScript to manipulate the contents of the actually visible Frame to reflect the data actually fetched from the server in that 0 sized frame. This is the technique which I used back in 2002, on the SOFTEC 2003’s, Macromedia Flash 5 based website, to submit a data entered by the user in a flash based form, to the server without posting back the page in which the Flash movie was loaded so as to provide the best possible user experience to the end user.
  • AJAX makes the application responsive by seamlessly sending an XMLHTTP request to the server without the need to post back the complete page. “By wisely using AJAX you can decrease the network traffic (and in turn increase the responsiveness) by just sending the request (and optionally the parameters) to the server and getting just the required data from the server and eventually displaying it to the end user in a neat fashion using JavaScript + HTML + DOM + CSS”.
  • AJAX “doesn’t eliminate the round-trip to the server”; it’s not like that all the data required by the page is sent to the client side when the page is first rendered, using such approach (might) result in performance hit (in most cases). It’s actually an “on-demand fetching of the required data based on user actions / timers in a seamless fashion to provide a better user experience”.
  • “Use AJAX in order to improve the user experience”. Keep the end use of your web application in mind, while you are engineering the application. This is the real key to make a successful web product / application.
  • “Use AJAX in order to minimize the overall network traffic” created by your web application.
  • “Don’t use AJAX to the extent that makes the response of your web application un-predictable for an end user”.

I will be providing a quick review of ASP.NET AJAX and its Programming Models in a week or so, keep your fingers crossed.

No comments: