Skip to main content
What is AJAX

What is AJAX

AJAX stands for Asynchronous JavaScript and XML. It describes a technique rather than a single technology: JavaScript sends an HTTP request, handles the response, and updates the DOM while the user continues to interact with the page.

The core idea

  1. The user triggers an event, such as typing or pressing a button.
  2. JavaScript creates a request to a URL.
  3. The browser sends the request without navigating away.
  4. The server returns data, often JSON.
  5. JavaScript updates the relevant part of the page.

Earlier implementations used XML payloads, which is where the name comes from. Most modern applications use JSON, HTML fragments, plain text, or binary data. The transport is still ordinary HTTP.

Asynchronous does not mean parallel execution

JavaScript runs on a single thread. An asynchronous request allows the browser to do other work while waiting for the network; it does not run your callback at the same instant as other code. Promises and event callbacks define when the response is handled.

fetch('/api/time')
  .then((response) => response.json())
  .then((data) => {
    document.querySelector('#clock').textContent = data.now;
  });

What AJAX is used for

  • Search suggestions and live filtering.
  • Saving a form without losing scroll position.
  • Loading more items at the end of a list.
  • Polling for new notifications or messages.
  • Uploading files with progress feedback.
  • Fetching dashboard data after the page loads.

What AJAX does not solve

It does not replace server-side validation, authorization, or database design. The browser is untrusted, and every endpoint must behave as if it were called directly. AJAX also complicates caching, history, accessibility, and error reporting, so those concerns need explicit design.

Relationship to single-page applications

A single-page application takes the idea further: navigation is handled by JavaScript and only data is fetched. That can feel fast, but it requires routing, state management, and careful handling of deep links. Many successful applications use AJAX selectively on server-rendered pages instead.