AJAX Basics

What Is AJAX? A Practical Introduction

Understand asynchronous browser requests, how AJAX works, and when to use it in modern web applications.

What Is AJAX?

AJAX stands for Asynchronous JavaScript and XML. The name is historical: modern applications commonly exchange JSON rather than XML. AJAX describes a pattern in which JavaScript sends an HTTP request without requiring the browser to reload the entire page.

How the request works

  1. A user action starts JavaScript code.
  2. The browser sends an HTTP request to a server endpoint.
  3. The server validates the request and returns a response, often JSON.
  4. JavaScript reads the response and updates the relevant part of the page.

A modern example

async function loadStatus() {
  const response = await fetch('/api/status.php');
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  const data = await response.json();
  document.querySelector('#status').textContent = data.message;
}

The endpoint should return an appropriate content type, such as application/json, and a meaningful HTTP status code.

When to use AJAX

Use it for live search, dependent form fields, inline updates, dashboards, and other interactions where a full page navigation would interrupt the task. Keep normal links and form submissions as useful fallbacks where practical.

Important considerations

Asynchronous requests still need server-side validation, authorization, CSRF protection for state changes, and safe output handling. Do not treat a request as trusted merely because it came from your own page.

Share this page Help other developers discover this resource.