HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [272]
The first thing is to figure out exactly what AJAX is and what it isn’t. It isn’t:
♦ A programming language: It isn’t one more language to learn along with the many others you encounter.
♦ New: Most of the technology used in AJAX isn’t really all that new; it’s the way the technology is being used that’s different.
♦ Remarkably different: For the most part, AJAX is about the same things you’ll see in the rest of this book: building compliant Web pages that interact with the user.
So you have to be wondering why people are so excited about AJAX. It’s a relatively simple thing, but it has the potential to change the way people think about Internet development. Here’s what it really is:
♦ Direct control of client-server communication: Rather than the automatic communication between client and server that happens with Web forms and server-side programs, AJAX is about managing this relationship more directly.
♦ Use of the XMLHttpRequest object: This is a special object that’s been built into the DOM of all major browsers for some time, but it wasn’t used heavily. The real innovation of AJAX was finding creative (and perhaps unintentional) uses for this heretofore virtually unknown utility.
♦ A closer relationship between client-side and server-side programming: Up to now, client-side programs (usually JavaScript) did their own thing, and server-side programs (PHP) operated without too much knowledge of each other. AJAX helps these two types of programming work together better.
♦ A series of libraries that facilitate this communication: AJAX isn’t that hard, but it does have a lot of details. Several great libraries have sprung up to simplify using AJAX technologies. You can find AJAX libraries for both client-side languages, like JavaScript, and server-side languages, like PHP.
Perhaps you’re making an online purchase with a shopping-cart mechanism.
In a typical (pre-AJAX) system, an entire Web page is downloaded to the user’s computer. There may be a limited amount of JavaScript-based interactivity, but anything that requires a data request needs to be sent back to the server. For example, if you’re on a shopping site and you want more information about that fur-lined fishbowl you’ve had your eye on, you might click the More Information button. This causes a request to be sent to the server, which builds an entirely new Web page for you containing your new request.
Every time you make a request, the system builds a whole new page on the fly. The client and server have a long-distance relationship.
In the old days when you wanted to manage your Web site’s content, you had to refresh each Web page — time-consuming to say the least. But with AJAX, you can update the content on a page without refreshing the page. Instead of the server sending an entire page response just to update a few words on the page, the server just sends the words you want to update and nothing else.
If you’re using an AJAX-enabled shopping cart, you might still click the fishbowl image. An AJAX request goes to the server and gets information about the fishbowl, which is immediately placed on the current page, without requiring a complete page refresh.
AJAX technology allows you to send a request to the server, which can then change just a small part of the page. With AJAX, you can have a whole bunch of smaller requests happening all the time, rather than a few big ones that rebuild the page in large, distracting flurries of activity.
To the user, this makes the Web page look more like traditional applications. This is the big appeal of AJAX: It allows Web applications to act more like desktop applications, even if these Web applications have complicated features like remote database access.
Google’s Gmail was the first major application to use AJAX, and it blew people away because it