Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Web Development

Approaches to AJAX


At a high-level of abstraction, Web applications look like a state machine where the user activity determines the next state. A graph of connections form all possible state transitions. What's a state, ultimately? A Web page-for example, an ASP.NET page-represents a state of the application. Moving from one state to the next implies that a brand new page is displayed. This model was good enough in the early days of the Web when applications were a collection of mostly static pages with limited graphics, no advertising, no animation and no multimedia contents. A decade ago, Microsoft started investigating technologies to make the state transition of a Web page more seamless and smooth. A first result was Remote Scripting (RS), which at its core, was nothing really different from the today's AJAX. But over the last decade, the creation of rich and powerful "tools" including XMLHttpRequest, Web services, and a standardized DOM has moved the goal of a dynamic web model into a practical, cross-platform reality.

With AJAX, you can achieve two key goals-refreshing portions of the page and invoking server-side code sending and receiving rich data thanks to a type system powered by JSON (JavaScript Object Notation). You might not notice it at first, but these two goals also herald two diametrically opposed, but not mutually exclusive, approaches to AJAX programming.

To refresh a portion of the page, you don't need to change much of your programming model and style. You just work with a bunch of new controls and let the back-end of your AJAX framework (be it ASP.NET AJAX Extensions or any other freely available technologies out there) to generate any script necessary to make the engine go. To invoke a server method, instead, you need a client-centric programming model. You need to take advantage of the full power of the JavaScript language.

This first approach seems ideal if you need to add AJAX capabilities to an existing application or just to a subset of pages. You don't need to rewrite anything; you just edit pages by identifying regions that need separate update logic and wrapping those into AJAX panels. It's a kind of zero-cost AJAX and is tremendously effective.

Second, even more effective from a purely traffic-oriented standpoint is any solution that leverages the JavaScript engine. The traffic between the browser and Web server is limited to just input parameters and return values; no viewstate, no event validation data, no extra burden of any sort. A client-centric approach requires a significant reengineering of existing pages and makes inevitable to design new pages in accordance with new patterns and principles.

A third possibility that somehow falls in between the two is represented by third-party suites of controls. There are some good ones on the market: ComponentArt's WebUI, Infragistics' NetAdvantage, Telerik's r.a.d.Controls just to name a few. [Ed: See Bringing the Desktop Application to the Web]

All of them are suites of rich UI server controls with an optional client-side object model to allow JavaScript programming. These controls shield you from the details of AJAX programming and propound a task-oriented approach to AJAX programming. Instead of reasoning in terms of updatable regions or page methods, you just think of UI features and user tasks. Need a pop-up menu, a tree-view, a smart grid? The libraries have this and much more and incorporate AJAX functionalities in any controls. In this way, Web pages get ajax-ified under your nose and you may not even realize it.

AJAX is a reality today and everybody can afford it. The real issue for developers and Web architects is finding out the most effective way to bring it into new and existing applications.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.