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.

1
  • 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? Commented Feb 26, 2010 at 20:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.