views:

303

answers:

1

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.

+1  A: 

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 http://stackoverflow.com/questions/136012/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.

BBonifield
I was able to get it going by using getJSON and pointing it to a dynamic file that checked the database with small script. Comet looks interesting, I will have to give it a try.
sfreelander