HTML and CSS Reference
In-Depth Information
chapter
18
An Introduction to
Ajax (with JSON)
18.1 Why Ajax?
JavaScript has gone through kind of a Renaissance of its own since this topic was first
published in 2002 largely due to the hype and promises it offers. Traditionally Web
applications have been somewhat clumsy and slow, and the level of interactivity and
usability inferior to their counterpart desktop applications, yet the number of Web
applications available continues to grow at an amazing rate. Part of that growth has been
spurred on by AJAX, “Asynchronous JavaScript and XML,” 1 not a new programming
language, but a methodology for creating fast, rich, user-friendly, and interactive Web
applications by allowing a Web page to request small fragments of information from the
server instead of an entire page. In this approach, asynchronous means that when a
request is initiated by the occurrence of a client event, JavaScript functions using Ajax
allow the browser to interact in the background directly with the server, and rather than
waiting for the server to respond, continue processing the page. The server will then
send its response to Ajax containing only the data that needs changing. Ajax in turn will
update that portion of the Web page. For example, if you are filling out a form, instead
of waiting until all the fields have been filled and the page submitted, now with Ajax,
the fields can be validated as they are filled and the user does not have to sit by waiting
for the page to reload before continuing what he or she was doing. This process is shown
in Figure 18.1.
As discussed in Chapter 1, “Introduction to JavaScript,” Google offers great exam-
ples of Ajax with Google Maps and Google Suggests, an application shared now by all
major browsers. (In fact, Ajax was made popular in 2005 with Google Suggest.) When
the you start searching in the Google search box, each time you press a key, Google
lists items that fit that sequence of letters. In a drop-down list, as if by magic, words
appear that contain those letters, and after each subsequent key press, the list changes,
1. The term Ajax was coined in 2005. Jesse James Garrett thought of the term while in the
shower. See http://en.wikipedia.org/wiki/Ajax _(programming).
797
 
 
 
Search WWH ::




Custom Search