Skip to main content

<Slushman />

unsplash-logo Alex

Troubleshooting WordPress AJAX

Published May 28, 2018

I was working with some AJAX functionality a while back and started writing down the problems and solutions I ran across so they were all in one place. Basically, this post is for my future self. I hope you find it useful as well. :)

Specific Problems

Function Always Returns 0

If you’re getting a “0” as the response from an AJAX call in the admin, it’s most likely one of three things:

403 Forbidden Error

Check the Nonce. You probably copied it from another function and it’s checking the wrong one.

Helpful Tip

The PHP function that processes the AJAX request has to echo something and should end with:

wp_die();

You can use that to return something you want to see, like what data was passed to the function.

To check an array, use this instead:

wp_die(print_r($some_array));

Share this post!

Check out the most recent posts:

How to Center in CSS

This is the ultimate guide to centering elements like images, text, and just about anything else using CSS.