tags:

views:

69

answers:

5

I am running a typical php-engined ajax webpage. I use echo to return a html string from the php code. My question is, if I have some other code after the echo, will those code get executed? Or echo behaves similar to exit, which immediately return and stop running the php code? Thanks.

+3  A: 

No, echo in no way exits, you normally have more than one echo in a script. exit does take a string argument that it will output before exiting, however, so you can do:

exit("your string here");

and it will output the string and exit

Michael Mrozek
A: 

No, echo would not. To exit after echoing things, you'd say

echo "Dear me, good bye!"; exit();

aharon
A: 

echo will simply return text to ajax javascript part; however the code after or before echo/echos will execute

sushil bharwani
A: 

No. PHP scripts are rendered in their entirety unless you explicitly exit them. ANY output on a script will be passed back to the ajax function if it was called through ajax.

echo 'This gets outputted<br />';
echo 'As does this';
Alex Zylman
A: 

If you must use a single file and you want your script to exit after performing ajax request with out having to add extra vars to your ajax url or evaluate vars to exit, i would suggest creating a function that performs your ajax, have the function return true on success, then do:

if(ajaxFunction($paramOne, $paramTwo)){exit();}
Babiker