Check for changes with jquery and a database
Posted
by
Steve
on Stack Overflow
See other posts from Stack Overflow
or by Steve
Published on 2012-10-26T10:55:40Z
Indexed on
2012/10/26
11:00 UTC
Read the original article
Hit count: 126
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.
© Stack Overflow or respective owner