How AJAX works

Ajax is a client pattern and for that reason it is powered by JavaScript. Unfortunately, JavaScript can’t exchange information with the server and can only post the page to it. This limitation can be overcome by using the XMLHTTP component of Ajax. XMLHTTP enables invoking the server asynchronously without posting the page and it also enables executing arbitrary code when the response from the server has been received. People think that x in the Ajax acronym means that XML is the protocol used. From technical point of view it is possible to use it, but XML is verbose and slow to process. There is a more optimized protocol named JSON which is a standard format for representing data. It has the great advantage of being integrated with the JavaScript engine. Thanks to JSON, data going to and coming back from the server is highly optimized.

There are hundreds of Ajax frameworks out there. All of them abstract the little differences between browsers regarding XMLHTTP use. Web developer can use one of these frameworks (ASP.NET Ajax, jQuery, MooTools, Prototype, etc.). The ASP.NET Ajax framework is the one realized by Microsoft to easily enable Ajax in ASP.NET applications. ASP.NET Ajax is separated into two main sections:

   -Server components – contain components to simplify development of Ajax behaviors using server-side code. The most important components in this section are the ScriptManager and UpdatePanel server controls.
   -Client components — contain a set of JavaScript classes that simplify Ajax calls and that interact with the server controls.

Server components are very simple. If Web developer works under application using server controls he/she can enable Ajax interaction, without even writing a single line of JavaScript code. The drawback of using server controls is that he/she doesn’t take full advantage of Ajax in terms of control over data and performance. When Web developer needs extreme performance and control, he/she has to use the client-side components.