You have to check the server at certain time interval for updates. You can use setInterval() function for that.
Below is a simple example and it updates the chat messages every 3 seconds in the innerhtml of a div named chatdiv.
You have to store the chatid in a hidden field named chatid.
function updateRow()
{
chatid = $("#chatid").val(); //hidden field which contains the current chat id.
$.ajax({
type: "POST",
url: "update.php",
data: {"chatid":chatid},
success: function (output) {
$('#chatdiv').html(output); //updates the output to a div
}
});
}
setInterval("updateRow()",3000); //call updateRow() function every 3 seconds.
In update.php you can fetch the chat messages from database and echo it.
For example,
$id = $_POST['chatid'];
$msg = $dbcon->queryUniqueValue("select message from chat where id=$id");
echo $msg;