Henrik Petterson Henrik Petterson - 4 months ago 24
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:

jQuery(this).html(data);


The PHP function which returns the data contains:

echo 'Please do this again.';
return;


By some reason, it outputs as:


Please do this again.0


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

Answer

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.

Comments