Reputation: 161
Right now I am using setInterval to refresh a div every few seconds. The page it is refreshing is data being pulled from a database in asp. I would like to have it only refresh the div when a change occurs in the database because the query is pretty large, but I've searched and could not find function or example for this. I figure the best way is to compare a session variable against the database, but I don't know how it can check that constantly, and then update the div when it changes.
Upvotes: 0
Views: 1513
Reputation: 5003
You might look into comet. Let your server tell the client what it needs instead of the client polling the server. http://ajaxian.com/archives/comet-a-new-approach-to-ajax-applications Comet and jQuery
Even if you didn't do comet, though, it seems the solution you provided in your own question would work. You just need to poll the server occasionally with a timestamp of the last polling, have it check a database timestamp to see if things have changed, and if so, respond accordingly, telling the client to go ahead and refresh the div.
Upvotes: 1