why ajax call return an extra 0 at end in WordPress?

If your use the returned data of an ajax call, you will find there is an unexpected extra 0 in the data. For example, if your action function is:
function myfunction()
{
echo "hello world";
}

you will get “hello world0”.

This is because after myfunction is executed, there is some other code executed that outputs the extra 0. Specifically, the last line in admin-ajax.php is die( '0' ); which outputs the extra 0.

To avoid this situation, you should use wp_send_json("hello world") in myfunction() instead of using echo.

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Leave a Reply