Prior to JavaScript and other client-side languages, Web browsers
operated as if they were HTML dumb terminals, merely presenting Web
pages generated on a server. For such pages, every user action requires
a full page refresh, with a round-trip over the Internet, which
degrades performance and thus user satisfaction. It may be fine for a
great many Web sites, but it is completely inadequate for
high-performance dynamic Web applications. Even e-commerce sites using
wholesale page refreshes every time, find that users can encounter all
kinds of problems. For instance, e-commerce sites often exhort
customers to not use their browser’s Back button while shopping online,
and to not click the Submit button twice should the purchase page fail
to respond. But what if the network hangs and customer does not know if
the purchase went through?
Traditional use of JavaScript made it possible to embed
functionality on the client-side, with far superior speed, by
eliminating network traffic. It was — and continues to be — ideal for
such needs as user form validation. But such JavaScript code does not
communicate with the server, and thus has no way of accessing
application data from a database, or even maintaining state in between
page refreshes.
AJAX Overview
AJAX (Asynchronous JavaScript and XML) evolved in an effort to solve
the aforesaid problems, by allowing the browser to communicate with the
server, behind the scenes, without having to refresh the entire page.
It accomplishes this by using JavaScript to only change that portion of
the current Web page that needs to be changed. AJAX can make the user’s
browser behave more like a desktop application, combining server
interaction with far greater performance than traditional server-side
languages. AJAX is asynchronous in the sense that the needed data is
obtained from the server and loaded without interfering with the
display and behavior of the current Web page. The data is requested
through use of the XMLHttpRequest object, and typically formatted in
XML — hence the rest of the acronym.
But raw AJAX programming can be quite difficult, partly because AJAX
code is typically quite daunting, and partly because Web browsers have
implemented JavaScript differently, despite a convergence upon
ECMAScript standards, promulgated by the European Computer
Manufacturers Association (ECMA). As a result, AJAX programmers can
spend much of their development time dealing with incompatibilities
among browsers and operating systems.