"refresh" Ajax div every x seconds, and show only when db is changed

Hello Experts!

I've been googling for some time now, and from what I can see, there is no way to automatically refresh a div, only if query result in the external page has changed.

But is it not possible to refresh every x seconds, but only display a refreshed result when the query result has changed?
Something like this: if varCount <> some variable then...

I've tried
if (req.status == 200)
//refresh div...
} else if {
(req.status == 304)
//do nothing...
but with no luck...
Who is Participating?
Gibu GeorgeChief Technology OfficerCommented:
What I understand is that when ever there is a change in data on the server side you want the change to be reflected on the browser, is this correct? If yes what you need to try is comet programming and ajax
NorgesbaatAuthor Commented:
Thx for answering!

I don't even know what "comet programming" is, but yes, you are right about what result I am looking for.
I was hoping that there was a way that my ajax function could fetch a variable value every time it refreshed, and fetch the data from the underlying php file. And then, if the value has changed, run the refreshed function, if not - do nothing...
I'm building a chat solution, and my ajax function runs the mysql_query every 10 seconds - with no problems. But if one thread has many comments its no good if the "ajax div" jumps to the first comment every 10 seconds, while the user maybe is reading the last post. Maybe its another solution to that problem instead, very happy for all inputs!
Gibu GeorgeChief Technology OfficerCommented:
Here is an example of comet using php

NorgesbaatAuthor Commented:
OK, I'll give it a try during the weekend, and come back here with comments/points.

And thx so very much for helping me!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.