I currently have an Ajax-based chat, which I am trying to streamline by only loading the chat script when an update occurs. Thus, nothing needs to keep loading if nothing has changed in the database.
My current logic says:
- JavaScript function fires every 1/2 second to get chat logs (
setInterval()
)
If nothing has changed, though, it seems fairly inefficient to keep calling it. Instead, what I'd like to do is:
- JavaScript function checks if there are any new logs in the database
- If YES - load the new logs, if NO - leave the currently displayed logs alone.
How would I go about this, though? The function I am currently using is:
function updateShouts() {
$('#chatArea').load('chat.php'); // load chat logs
}
setInterval("updateShouts()", 500); // call function every half a second