I have this php code
<?php
$status_code=1;
echo "<?xml version=\"1.0\"?>\n";
echo "<response>\n";
echo "\t<status>$status_code</status>\n";
echo "\t<time>" . time() . "</time>\n";
if ($status_code == 1) {
echo "\t<message>\n";
echo "\t\t<author>Vlad</author>\n";
echo "\t\t<text>Ova e poraka</text>\n";
echo "\t</message>\n";
}
echo "</response>";
?>
Why I don’t get the printed xml code in browser?
Also is it good practice to create ajax requests by printing the xml code directly in php or should I use some xml php function to create xml code?
I wanted to create a chat system by using jquery, ajax, php and mysql using this tutorial, but I get error that the above printed xml is not well formed
As the others have said, you need to give the browser a header to let it know how to display the page.
As for xml functions, have a look at the PHP SimpleXMLElement