The benefits of AJAX
AJAX makes it possible to create dynamic applications that load and run faster and also use fewer network and server resources. The goal of AJAX is to allow changes to a page without having to reload the entire page.
Using AJAX makes it possible to create applications that are quite fast without loading the server down with large requests. All the server has to do is send a small piece of data to the caller when requested. This small piece of data travels faster over the network, which means that request latency is also smaller.
One of the bigger reasons to use AJAX is that it’s standards-based (created and administered by a standards group). There isn’t some large company out there that controls AJAX. Because it’s standards-based, AJAX runs on any newer browser and platform combination that supports the standards it uses. AJAX relies on these standards:
Cascading Style Sheets (CSS): Using CSS makes it possible to create special effects during data updates. In addition, CSS makes the new data fit in with the existing page content.
eXtensible Markup Language (XML): Any update is going to require some sort of data. XML is a perfect choice because it works anywhere.
XMLHttpRequest object: Communication with the server requires a connection, and the XMLHttpRequest object creates this connection. AJAX performs its tasks asynchronously.
How AJAX works
AJAX doesn’t perform magic. There’s nothing behind the scenes that doesn’t make sense once you understand it. AJAX performs the task over a network wire rather than locally in the same page or an external page in the same folder. Here’s the sequence of events that occur when using AJAX.
An event occurs at the browser. (The nature of the event is irrelevant but generally involves a data request of some sort.)
The server creates a response and sends it back to the browser.
The browser’s callback function provided with the original request receives the response from the server.
The callback function performs any required post-processing of the response.
An update of the information onscreen occurs, and the user sees the result.