4.2. Prototype

One JavaScript library that has gained considerable popularity with the emergence of Ajax is Prototype, available at http://prototype.conio.net. Prototype is not simply an Ajax library; it is actually a complete JavaScript framework designed to ease the development of all types of JavaScript solutions.

It is beyond the scope of this book to fully explore all of Prototype's features, so the focus here is on its Ajax capabilities.

4.2.1. The Ajax.Request Object

Most of Prototype's low-level Ajax features are contained on the aptly named Ajax object. The Ajax object has several properties containing methods and constructors for useful objects. The simplest object, and the most similar to XHR, is the Ajax.Request object, which has the following constructor:

request = new Ajax.Request(url, options);

The first argument is the URL to send the request to. The second argument is an object containing any number of options for the request. As soon as the creation of the Ajax.Request object is complete, the request is sent (think of it as combining XHR's open() and send() methods in one call). For this reason, the options object is very important.

4.2.2. The Options Object

The options object, as used in the Ajax.Request() constructor, contains all of the information about the request except for the URL. In its simplest form, the options object contains the following properties:

  • method: Either "get" or "post."

  • parameters: The data to be sent to the URL. Typically, a URL-encoded ...

Get Professional Ajax, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.