Chapter 4. Ajax

4.1. Ajax Overview
4.2. AjaxBehavior
4.3. AjaxBehavior Execution
4.4. First Ajax Example
4.4.1. Ajax Trace Log
4.4.2. Ajax Trace Log - No Ajax Target Control Found
4.4.3. Ajax Trace Log - No Target AjaxBehavior Found
4.5. Ajax Page Action
4.6. Ajax Response Types
4.7. Ajax Error Handling

4.1. Ajax Overview

Ajax is a method of using JavaScript to perform a GET or POST request and return a result without reloading the whole page.

For an introduction on Ajax please see the following articles:

Ajax is a client-side technology for creating interactive web applications. The JavaScript XMLHttpRequest object is used to perform GET and POST requests and the server can send back a response that can be processed in the browser.

Click on the other hand is a server-side technology that can handle and process incoming Ajax requests and send a response back to the browser.

Please note: Click is responsible for handling server-side requests. It is up to you to develop the client-side logic necessary to make the Ajax request, process the server response and handle errors. This is easier than it sounds though as there is a wide range of free JavaScript libraries and plugins available to help develop rich HTML front-ened. Since Click is a stateless framework and Page URLs are bookmarkable, it is easy to integrate Click with existing JavaScript technologies such as: jQuery, Prototype and MooTools to name a few.

It is also possible to write custom AjaxBehaviors (covered later) that renders the client-side code necessary to initiate Ajax requests and handle Ajax responses and errors. In fact once you become familiar Click's Ajax handling, you will likely create custom AjaxBehaviors to streamline and encapsulate your client-side code.

In this chapter we'll look at the Ajax support provided by Click. There are two basic ways to handle and process Ajax requests:

  • AjaxBehavior - AjaxBehavior is a specialized Behavior that enables Controls to handle and respond to Ajax requests

  • Page Actions - Page Actions was covered earlier and provides a simple way to handle and respond to Ajax requests