Imagine you're browsing a bustling online bookstore (like Goodreads). You see a “Want to Read” button for a book you’d like to mark on your profile. In the old days of the Web, clicking that button would trigger a full page reload—which might seem overkill if all you wanted was a small text update on the page. Thanks to AJAX (Asynchronous JavaScript and XML), modern web apps can interact with the server in the background, update only what’s needed, and keep you immersed in the same page.
In this lesson, we’ll examine how the web evolved from classic full page reloads to AJAX, saving time, bandwidth, and effort in the process.
Early websites relied on a simple model: every time you made a request—such as submitting a form or navigating to another page—the browser would fetch an entirely new HTML document from the server. For example:
This served basic needs well. But as web apps got more interactive—like showing live search results, quick updates to user statuses, or chat messages—reloading the entire page felt slow, disruptive, and clunky.
Imagine just wanting to mark a book as “Want to Read.” With old-school full reloads:
Rebuilding and reloading a whole page just to show that a single button changed its text? Inefficient. Enter AJAX.
AJAX is a group of technologies that enable background communications between the browser and server without reloading the page. Instead of retrieving a whole HTML page, the server sends back data. JavaScript in the browser processes that data and updates only the parts of the page that need changing.
For instance, marking a book “Want to Read” could work like this:
{"status": "Want to Read"}).The result is a smoother, faster user experience. Your scroll position or any other interaction on the page remains intact.
Asynchronous JavaScript and XML is a bit of a historical name, because:
Pros of AJAX:
Complexity Trade-offs:
Over time, libraries like jQuery (with $.ajax) and modern frameworks like
React, Vue, or Angular have simplified AJAX usage. This evolution contributed to
“single-page applications,” where a site loads once and dynamically updates as needed.
In short, AJAX revolutionized web apps by allowing them to update only the parts of the page that change, resulting in a faster, more seamless user experience. Here are the main points:
Next, we’ll dive deeper into the nitty-gritty of how AJAX sends requests and receives responses, plus how you can use JavaScript to manage these requests in real-world scenarios.