What AJAX is

AJAX stands for Asynchronous JavaScript and XML. It is a way for a page to talk to the server in the background, not a separate language or program. The browser asks the server only for the data it needs and changes just part of the page. The whole page does not have to reload, so the site responds quickly.

“Asynchronous” means you can keep using the page while it waits for the server to reply.

AJAX examples you already know

  • Search suggestions: Google or an online shop offers results while you are still typing.
  • Add to basket: the product appears in the basket without you going to another page.
  • Product filters: tick a colour or size and the list redraws straight away.
  • Infinite scrolling: more posts load when you reach the bottom.
  • Form submission: the thank-you message appears right on the page.
  • Maps, chat, notifications: the content keeps updating.

How AJAX works

  1. The user does something, for example types a letter or clicks a button.
  2. JavaScript in the browser sends a request to the server.
  3. The server processes the request and returns only the data, nowadays usually in JSON format, in the past in XML.
  4. JavaScript inserts the result into the page.

The server often makes the data available through an API. This used to be done with the XMLHttpRequest object; today it is mostly the newer fetch function.

Pros and cons

  • Speed: less data is transferred and the page responds immediately.
  • Easier to use: the website behaves like an app.
  • Less server load: the whole page is not generated again.
  • Watch out for SEO: search engines may not see content that only loads after a click. Important text and links should be in the page from the start.
  • The Back button: if implemented badly, it does not behave as expected and the page address cannot be shared.

A large part of today’s frontend is built on AJAX, including frameworks such as React and Vue.

Interactive websites and apps

I build fast filters, calculators, booking systems and client portals as web applications. For WordPress and WooCommerce I can create interactive features as a custom plugin.