concept Ajax in category javascript

appears as: Ajax, Ajax, n Ajax
Prototype and Scriptaculous in Action

This is an excerpt from Manning's book Prototype and Scriptaculous in Action.

Listing 1.2. Ajax call code for Rating object

1.1. A brief history of Ajax

Ajax is a recently coined term used to describe the business of programming highly interactive web-based interfaces using nothing more than HTML, Cascading Style Sheets (CSS), and a good dose of JavaScript. People have been writing this sort of application for several years, but Jesse James Garrett only christened the practice in February 2005, and it has since gone on to become one of the hot tech topics.

The adoption of Ajax by the web community has been rapid, and the landscape has changed considerably. Prototype and Scriptaculous are in the thick of these changes, and it’s useful to see where they’re coming from. So, let’s briefly put our tech-archaeologist hats on and dig through the history of Ajax.

At the heart of Ajax is the ability to make asynchronous requests to the server, and thereby separate communications from the user interface. The impact of this on usability can’t be overstated. It allows the user to get on with the job while the web app gets on with its own housekeeping duties, without the two coming into conflict. Increasing usability not only makes the current round of web apps easier to use, it extends the reach of the web app to far more demanding usage scenarios, right up to the mission-critical apps that are used intensively, day-in, day-out.

In chapter 1, we saw how complicated dealing with the XMLHttpRequest object could be, and we offered a sneak preview of how Prototype’s Ajax helper classes could make it that much easier to work with. In this chapter, we’ll unpack Prototype’s support for Ajax more comprehensively, and examine the full range of options that it offers. (This and the next chapter deal with Prototype. We’ll start to work with Scriptaculous in chapter 5.) Once you’ve mastered the contents of this chapter, you’ll not only be able to improve the usability of your apps by an order of magnitude, you’ll get to stay sane and go home on time.

In chapter 2, we introduced the QuickGallery application that we’re going to use as a test-bed for Prototype’s Ajax capabilities. As we left it at the end of chapter 2, QuickGallery was able to function without Ajax, but it suffered from a lack of responsiveness owing to the need to refresh the entire page every time we made a request to the server. We’ll pick up from there in this chapter, and illustrate how to go about separating the communication from the presentation, and get rid of those pesky full-page refreshes.

def my_action
  if request.xml_http_request?
    # handle Ajax request
  else
    # handle regular form submission
  end
end