Will PHP code come out after echo for ajax?

I am launching a typical ajax webpage with php-engined. I use echo to return an html string from php code. My question is, if I have another code after the echo, will this code be executed? Or does echo behave similarly to exit, which immediately returns and stops php code execution? Thanks.

+6
ajax php
source share
5 answers

No, echo does not exit in any way, you usually have more than one echo in a script. exit takes a string argument that will be output before exiting, so you can do:

 exit("your string here"); 

and it will output a line and exit

+13
source share

No, there will be no echo. To get out of the echo, you could say

echo "Dear, goodbye!"; Exit();

+1
source share

echo will just return the text to the javascript part of ajax; however, the code after or before echo / echos executes

0
source share

Not. PHP scripts are fully displayed unless you explicitly exit them. Any output to the script will be passed back to the ajax function if it was called via ajax.

 echo 'This gets outputted<br />'; echo 'As does this'; 
0
source share

If you have to use one file and you want your script to exit after executing an ajax request without having to add additional vars to the ajax url or evaluate the vars to exit, I would suggest creating a function that executes your ajax, the function returns true if success, then do:

 if(ajaxFunction($paramOne, $paramTwo)){exit();} 
0
source share

All Articles