Check for changes with jquery and a database
- by Steve
I am doing a notification system. When a new post is published, users will be notified immediately by an small notification on the screen.
I am currently using this:
setInterval(function(){
checkForChanges();
}, 2*1000);
function checkForChanges(){
$.post("http://"+ document.domain + "/posts/checkForChanges/",
function(dat){
if(dat>0){
....
/*create notification*/
}
});
}
And i was wondering if this is the correct way to do it or not. Because, this is calling a PHP function every 2 seconds and making a query to the database.
In case there are no new changes, it won't do anything...
Thanks.