AJAX (Asynchronous JavaScript and XML)

AJAX is a technique for creating fast and dynamic web pages by exchanging data with a server asynchronously without reloading the entire page. Despite its name, modern AJAX implementations commonly use JSON instead of XML.

How It Works

AJAX allows web applications to:

  • Send requests to a server in the background
  • Receive and process responses without page refresh
  • Update parts of a page dynamically

Modern Implementation

While the original AJAX used XMLHttpRequest, modern applications typically use the Fetch API for cleaner, promise-based asynchronous requests.

Example

javascript
// Modern AJAX with Fetch API
async function loadUserData(userId) {
  try {
    const response = await fetch(`/api/users/${userId}`)
    const userData = await response.json()
    updateUI(userData)
  } catch (error) {
    console.error('Failed to load user data:', error)
  }
}

Learn More