I have a simple ajax call inside a javascript function to a php file, which searches the DB and returns formatted html. Alls fine, but for some reason the returned html is being wrongly formatted.
Javascript:
$.ajax(
{
url: "getItems.php?lastID=10",
success: function(html)
{
if(html)
{
$("#main").prepend(html);
}
}
});
getItems.php
<?php
mysql_connect();
$lastID = $_GET['lastID'];
$result = mysql_query("SELECT ...");
while ($row = mysql_fetch_assoc($result))
{
echo '<span class="iteminfo"> ';
echo '<a class="username" href="http://x.com/'.$row['UserName'].'" target="_blank"/>'.$row['UserName'].'</a><br/>';
echo '<a class="status" href="http://x.com/'.$row['UserName'].'/c/'" target="_blank" />'.$created_at.'</a></span>';
}
?>
which should return (and it returns this correctly in Firebug)
<span class="iteminfo">
<a class="username" href="http://x.com/username" target="_blank"/>username</a><br/>
<a class="status" href="http://x.com/username/c/" target="_blank" />the date</a>
</span>
but instead its outputting:
<span class="iteminfo">
<a class="username" href="http://x.com/username" target="_blank"/></a>username<br/>
<a class="status" href="http://x.com/username/c/" target="_blank" /></a>the date
</span>
and I’ve no idea why.
You have closed a tag wrong manner
but u have used