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

Posted on 2009-04-17
Last Modified: 2013-12-29
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...
Question by:Norgesbaat
    LVL 12

    Accepted Solution

    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

    Author Comment

    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!
    LVL 12

    Assisted Solution

    by:Gibu George
    Here is an example of comet using php

    Author Comment

    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Hello World !, Thanks : My Sincere thanks to @Michael Male who encouraged me to write an article on this in my  blog ( Introduction:       There are several technical issues a developer may face in his…
    Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
    This video discusses moving either the default database or any database to a new volume.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now