admin-ajax.php is the workhorse endpoint for WordPress JS-driven features — autosave, heartbeat, Gutenberg editor saves, every plugin’s quick actions. When it returns 400 or 500, the failure is almost never about the network. It’s nonce, capability, or a PHP fatal in the action handler. Each leaves a distinct fingerprint.
What’s happening
A WordPress AJAX call posts to /wp-admin/admin-ajax.php with at least two fields: action (which determines which callback runs) and _wpnonce or nonce (which proves the request came from a logged-in user). WordPress dispatches to wp_ajax_{action} or wp_ajax_nopriv_{action} based on whether the user is logged in. If no callback is registered, WordPress sends 0 and a 200 status — confusingly successful from HTTP’s perspective. If the callback runs but wp_die()s on a permission check, you get a 403. If it fatals, you get a 500.
The four common failures: nonce expired (returns -1 or 403), capability check failed (returns 0 or 403), the action wasn’t registered for logged-in vs anonymous users, or the action ran and threw a PHP fatal mid-execution.
How to verify
# Capture cookies from a real login:
curl -i -c cookies.txt -d "log=user&pwd=pass" https://example.com/wp-login.php
# Get a fresh nonce:
NONCE=$(wp eval "echo wp_create_nonce('my_action');")
# Replay the AJAX request:
curl -i -b cookies.txt -X POST \
-d "action=my_action&_wpnonce=$NONCE&data=test" \
https://example.com/wp-admin/admin-ajax.php
In DevTools, F12 > Network > filter by “admin-ajax”. Reproduce the action. The Headers panel shows form data sent, the Response panel shows what came back. WordPress AJAX responses are often plain text — 0, -1, or JSON.
The fix
- Decode the response.
0means no callback was registered for that action.-1means nonce failed. Empty body usually means awp_die()after capability check. Non-200 status means PHP fatal or web server error. - Verify the action name. The hook is
wp_ajax_{your-action}for logged-in users,wp_ajax_nopriv_{your-action}for anonymous. If your front-end form is posted by anonymous users, you need both hooks. - Refresh nonces on long-lived pages. Nonces expire after 24 hours by default. On a long-open admin tab, the nonce dies. Use the heartbeat to refresh nonces, or detect a
-1response and reload. - Enable WP_DEBUG_LOG. A PHP fatal in an AJAX handler returns 500 to the browser but writes the full trace to
debug.log. Read that file withtail -fwhile reproducing. - Check capability requirements.
current_user_can('manage_options')returns false for non-admin users. A capability mismatch on a UI element shown to editors is a common failure. - Watch out for output before headers. A
print_rorvar_dumpbeforewp_send_json_success()corrupts the JSON response and the browser parses it as text. Use Query Monitor’s PHP Errors panel to find stray output.
For sites where AJAX-driven plugins fail in production, Stack Harbor instruments admin-ajax as part of enterprise WordPress observability. To debug a current AJAX failure, book a consult.