php return to ajax?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

php return to ajax?

Post by manRay »

I was wondering what the proper way to return something from a php script to an ajax script is.
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Re: php return to ajax?

Post by liljester »

ive used print or echo
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: php return to ajax?

Post by Jonah Bron »

Anything that goes to the output buffer is sent to Ajax. As liljester said, anything you echo/print, or even just plain HTML/text will be visible to your Javascript.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php return to ajax?

Post by AbraCadaver »

Yes, so if you just need some text etc. sent back then echo as is. If you need more structure such as an array or object of DB records for example, then you can use json_encode().
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply