I've been learning about AJAX and making my first requests from my local server, only requesting an XML or HTML file, nothing too difficult. I'm working with PHP now, and I understand it fairly well, it's not too much different than using the XML/HTML.
While going through tutorials I've seen a few different ways of returning information back to JavaScript; I am curious as to whether or not there is a 'right' way, or even a 'more correct' way of doing this. Thus far I have come across three methods:
someFile.php:
<?php
$foo = $_GET['bar'];
// manipulate $foo
exit($foo); // method 1
echo $foo; // method 2
// method 3:
?>
<div id='baz'>
<p>
Some output to be returned to JavaScript as the 'responseText'
property of the AJAX request.
</p>
<p>
<?php echo $foo ?>
</p>
</div>
I'm simply unsure of the process of returning information from the server back to the browser. What all gets sent back? Anything that would be displayed if this were a page that people were actually supposed to visit? Thanks for you help!