Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2009-04-17
Medium Priority
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
  • 2
  • 2
LVL 12

Accepted Solution

Gibu George earned 2000 total points
ID: 24166999
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

ID: 24167416
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
Gibu George earned 2000 total points
ID: 24167729
Here is an example of comet using php


Author Comment

ID: 24168091
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!

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

571 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