I'm having trouble getting this div to automatically update using jquery - it's essentially a "chat" feature that would have the page refresh every 2 seconds.
Here's the problematic jquery code - I've tried several variances of this with no luck, so completely rewriting it differently is more than welcomed.
function updateChat() {
$.get("chat_data.php", function(data) {
$("div#chattable").html(data);
});
window.setTimeout("updateChat();", 2000);
}
$(document).ready(function() {
updateChat();
});
Here's the div code which gets the data from "chat_data.php" - which it should be updating:
<div id="chattable">
<?php include("js/chat_data.php"); ?>
</div>
And just for reference, here's the code (using codeigniter) of "chat_data.php".
<?php foreach($query->result() as $row):
echo "<div class='chatrow'>";
echo "<div class='chattime'>".date("[M.d] g:ia",strtotime($row->time))."</div>";
echo "<div class='chatnamematch'>[".$row->name."]</div>";
echo "<div class='chatbody'>".$row->body."</div>";
echo "</div>";
endforeach; ?>