Chapter 8. Large-Scale Ajax
Ajax (Asynchronous JavaScript and XML) is not so much a new technology
as a set of existing technologies used together in a new way, bound together
by a mechanism that lets you communicate between the browser and server
without reloading the entire page. In its most fundamental form, Ajax
requires that you understand only one new piece: the XMLHttpRequest
object in JavaScript (or its
equivalent depending on the browser). This is the object that allows you to
make a connection back to the originating server to request additional data.
Once you receive the data, you can use it to adjust only the portion of the
page that you need to update.
Although the object’s name and the term “Ajax” itself imply
that XML is the only format for exchanging data, there are others.
JSON is especially good because it lets you pass a string of
JavaScript on which you call json_parse
(which you can download from http://json.org/json_parse.js), to yield a JavaScript
object.
Certain practices simplify working with Ajax. Usually, it’s helpful to
load a library that abstracts the XMLHttpRequest
object. Fortunately, there are
several libraries that help with this. In addition, within the browser, the
MVC design pattern is a good model for maintaining a clear separation
between data changes and updates to a presentation. On the server, the same
principles discussed in Chapter 6 for managing data for complete pages can also provide a good structure for data in Ajax requests. These ideas ...
Get Developing Large Web Applications 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.