0

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.

Charles Sprayberry
  • 7,580
  • 2
  • 37
  • 49
sfreelander
  • 161
  • 1
  • 2
  • 11
  • I think I might be able to do it by using cookies. I can have a small script checking the database constantly for a change in the field and comparing it with a cookie, which is also being monitored by the jquery cookie plugin. If the data changes, the cookie is updated, telling jquery to refresh the div. Any thoughts? – sfreelander Feb 26 '10 at 20:01

1 Answers1

1

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.

Community
  • 1
  • 1
BBonifield
  • 4,873
  • 16
  • 36
  • 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 Feb 27 '10 at 19:32