Henrik Petterson Henrik Petterson - 2 months ago 8x
jQuery Question

JS adds a zero at the end

On my jQuery ajax function, I output the data returned from a PHP script like this:


The PHP function which returns the data contains:

echo 'Please do this again.';

By some reason, it outputs as:

Please do this again.0

So it adds a
at the end. Why does this happen and what can I do to fix it?


Quick Answer (I will explain more later):

With return; you produce that extra output, that gets interpreted to 0.

Eighter remove that return; or replace it with an exit; to stop php from executing.

Other possibility is to do return 'Please do this again.'; if you are outside of functions.