Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will php code exit after echo for ajax?

Tags:

ajax

php

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.

like image 807
Steve Avatar asked May 26 '10 00:05

Steve


People also ask

Where does PHP echo output go?

Echo sends output to the output buffer, If it's embedded in HTML (which is also being sent to the output buffer) then it appears that it writes that to the "source".

Can I write PHP code in AJAX?

No, not directly, as JavaScript ist executed on the client side, and PHP is executed on the server. A workaround would be to send another AJAX-Request from your success-function.

How do you terminate a PHP program?

The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script.

What does exit () do in PHP?

The exit() function prints a message and terminates the current script.


1 Answers

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

like image 196
Michael Mrozek Avatar answered Sep 29 '22 02:09

Michael Mrozek