Web Programming

Chapter 8: jQuery; AJAX

AJAX- Introduction

(Note: This sub-chapter is a gentle introduction to AJAX. We will not cover details in this chapter. This reading should get you started, AJAX in itself is a huge topic and requires at least 5-6 weeks of notes to cover it in depth.)

 

What?

 

AJAX (Asynchronous JavaScript and XML), is a group of inter-related web development techniques used for creating interactive web applications.

 

A primary characteristic is the increased responsiveness and interactivity of web pages achieved by exchanging small amounts of data with the server "behind the scenes" so that the entire web page does not have to be reloaded each time the user performs an action. This is intended to increase the web page's interactivity, speed, functionality, and usability.

 

AJAX is asynchronous in that extra data is requested from the server and loaded in the background without interfering with the display and behavior of the existing page. JavaScript is the scripting language in which AJAX function calls are usually made.

 

Data is retrieved using the XMLHttpRequest object that is available to scripting languages run in modern browsers.

 

AJAX is a cross-platform technique usable on many different operating systems, computer architectures, and web browsers as it is based on open standards such as JavaScript and the DOM. There are free and open source implementations of suitable frameworks and libraries.

 

Why?

 

Web applications can be located at one single server location and accessed by all. Any changes/improvements to the functionality can be delivered in one central location and take effect immediately. Far more control is left in the hands of the developers, and they can quite often continue to create and maintain a superior product. Naturally, everything comes with a price. While delivering an application from a central server location is quite nice from a maintenance point of view, the problem arises that the client needs a means to access said point of entry. The Internet provides a wonderful way to do this, but the question of speed comes into play immediately.

While a client using Microsoft Word, for example, can simply click a button on their computer to fire it up and receive an instant response, applications built on the Internet require a connection to said application to use it. While high-speed Internet is gainingmore and more ground every day, a vast majority of Internet users are still making use of the much slower 56 Kbps (and slower) modems. Therefore, even if the software can quickly process information on the server, it may take a considerable amount of time to deliver it to the end user.

Combine this issue with the need to refresh the page every time a server response is required, and you can have some very frustrating issues for the end user of an Internet application. A need is definitely in place for web applications that contain the benefits of deliverability with the speed of a desktop application. As mentioned, Flash provides such a means, to an extent, through its powerful ActionScript language, but you need to be a jack-of-all-trades to effectively use it. DHTML (= Dynamic HTML, achieved by a mix of XHTML , CSS and JavaScript) provides a means to do this through the use of JavaScript, but the code to do so is rather restrictive.

 

Even worse, you often have to deal with browsers that refuse to cooperate with a real set of standards (or rather, fail to follow the standards). Thankfully, though, there is a solution to these problems: Ajax. Dubbed Asynchronous JavaScript and XML by Jesse James Garrett, and made popular largely by such web applications as Google’s Gmail, Ajax is a means to making server-side requests with seamless page-loading and little to no need for full page refreshes.