How do I make it so that my javascript only gets info from my database when its updated?
For example :
Let's say im programming a chat system and I only want the messages that are sent to the chat database after the user has logged onto the website to display in his chat box.
Meaning maybe Bob types a message and its sent to everyone on the website at that moment. John enters the session a while later and does not get the message.
I want that to happen ^
I currently have a javascript on interval getting data from the database every second but that causes the entire history of messages to be displayed in the user's textbox. Can anyone help me with this? Greatly appreciated.
function getMessages(){
$.get('GetMessages.php',function(data){
$(".chatMessages").html(data);
});
}
setInterval(function(){
getMessages();
},500);
EDIT 1
No, I don't can't use long polling as I'm using apache to host it and i doubt i can mount socket.io onto apache :/
is there no other method?