Book a call Free rebuild

AJAX

May 16, 2025 Updated November 16, 2026 3 min read

WordPress glossaryAJAX (Asynchronous JavaScript and XML) lets a page send and receive data from the server in the background, so part of it updates without a full reload. WordPress handles AJAX requests through admin-ajax.php and the REST API.

AJAX is a way of building pages that talk to the server without reloading. When someone clicks a button, types in a search box, or filters a product list, JavaScript sends a small request in the background, gets data back, and updates just the part of the page that needs to change. Everything else stays where it is, including the scroll position and anything the visitor has typed.

The name stands for Asynchronous JavaScript and XML, but it describes a technique rather than a single technology, and the XML part is mostly historical. Today the data usually travels as JSON, and the request is usually made with the browser's fetch() API rather than the older XMLHttpRequest object.

A short history

The building blocks existed before the name. Microsoft added the XMLHTTP object to Internet Explorer 5 in 1999, and other browsers followed with XMLHttpRequest. Jesse James Garrett coined the term "Ajax" in 2005 to describe the pattern behind apps such as Gmail and Google Maps, which felt far more responsive than the click-and-wait sites of the time. The pattern became so common that it is now simply how most of the web works.

How it works

  1. A visitor does something: clicks, types, scrolls, or submits a form.
  2. JavaScript sends an HTTP request to the server in the background.
  3. The server runs some code (PHP, in WordPress) and returns data, usually JSON or a fragment of HTML.
  4. JavaScript reads the response and updates the page's DOM without a full reload.

"Asynchronous" means the page does not freeze while it waits. The visitor can keep reading or typing, and the update arrives when the response does.

Everyday examples

  • Search suggestions that appear as you type.
  • Add-to-cart buttons that update the mini cart without leaving the product page.
  • Product filters and "load more" buttons on shop and blog archives.
  • Form validation that checks an email or username before the form is submitted.
  • Likes, votes, and comments that post instantly.

AJAX in WordPress

WordPress has two routes for AJAX requests.

admin-ajax.php is the original one, and much of the admin still uses it: approving a comment from the list, adding a category in the classic editor, and the Heartbeat API all go through it. A plugin registers a handler with the wp_ajax_{action} hook for logged-in users and wp_ajax_nopriv_{action} for visitors, and its JavaScript posts to /wp-admin/admin-ajax.php with that action name.

The REST API gives each feature its own endpoint under /wp-json/, with a permission callback and structured JSON responses. The block editor works almost entirely through it. For new code, many developers prefer it because the endpoints are easier to secure, test, and document.

Whichever route a site uses, every request boots WordPress and runs PHP, and these requests usually bypass page caching. A theme or plugin that fires AJAX calls on every page view, or on a timer, can put real load on a server. When we audit a slow site, a busy admin-ajax.php in the access logs is one of the first things we look for.

Security

An AJAX handler is a public URL that changes or returns data, so it needs the same care as a form handler.

  • Check a nonce (for example with check_ajax_referer()) to protect against cross-site request forgery.
  • Check the user's capability with current_user_can() before doing anything privileged. A nonce proves intent, not permission.
  • Sanitize everything that comes in and escape everything that goes out.
  • Never register a sensitive action on the nopriv hook.

SEO and limitations

Google renders JavaScript, but content that only appears after a click, a scroll, or another interaction may never be seen by crawlers. Anything that matters for search, such as product descriptions, article text, and paginated archive links, should be in the HTML the server sends or reachable through ordinary links. AJAX also depends on JavaScript, so core actions like checkout and contact forms should still work, or fail clearly, when a script breaks.

Source: WordPress Plugin Handbook, AJAX.

WP Services

WordPress services at revolutionary pricing.

Productized WordPress services, from builds to care, delivered by Seahawk and tracked in one app. For the WordPress lovers.