While trying to execute AJAX in a custom WordPress theme the response always returns 0.

Solution 1

Action is set outside of ajax data in javascript file and it needs to be defined inside of it

Solution 2

The functions could not be spelled the same way

Solution 3

Some themes use classes while others don’t. Yours doesn’t use a class and you’ve copied and pasted code from a theme that does. in short, you are using add_action( ‘wp_ajax_your_function’, array(&$this, ‘your_function’)); when not using a class. To fix it, use add_action( ‘wp_ajax_your_function’, ‘your_function’);

Solution 4

Your php function doesn’t call exit() or die() when it is finished