I've recently been working on a shoutbox that refreshes every 3 seconds but I want the time values to update every time the request was finished. So if the value was "3 seconds ago" I want it to show "6 seconds ago". At the moment it is able to load new messages but it doesn't update the value itself. I've tried it myself as well as you can see on line 12.
function readChatMessages() {
$.ajax({
url: "/inc/player_chat_output.php?latestid=" + lastid
}).done(function(data) {
var obj = JSON.parse(data);
for(var i = 0; i < obj.length; i++)
{
lastid = obj[i].id;
$("#chatbody").prepend("<tr class='chatrow'><td><a href='/user/" + obj[i].author + "'>" + obj[i].author + "</a></td><td>" + obj[i].message + "</td><td id='chatrowtime-" + obj[i].id + "'>" + getJSAgoFromUNIX(obj[i].date) + "</td><br></tr>");
document.getElementById("chatrowtime-" + obj[i].id).innerHTML = getJSAgoFromUNIX(obj[i].date);
$(".chatrow").each(function(index) {
document.getElementById("chatrowtime-" + obj[i].id).innerHTML = getJSAgoFromUNIX(obj[i].date);
if(index > 14)$(this).remove();
});
}
});
}
Aucun commentaire:
Enregistrer un commentaire