Skip to main content

Why my WP_AJAX returning Zero (0) with my response?

1 min read

Wrote a start up post on WP_Ajax last time.

Some of you may still surprise, why the callback function for WP_Ajax returning an additional 0 or something else which is very unwanted at the end of your own response.

It's annoying and at first you may get caught confused.

Actually the thing happened for a little different nature of WP_Ajax.

We usually use a return to end a function, but for callback function of WP_Ajax you are doing this wrong.
You'll have to use die() or exit at the end of your code instead of return for a clean output.

Only this way you can have a clean output without any 0 or something else.