0

Hi everyone.

I would like to implement a counter using ajax that will act like this:
The script will send a XMLHttpRequest every x seconds which will return a value from a mysql database.
Using the current and previous value retrieved from the server, the script will increase the counter, in order to reach the new value in the x second interval between the server requests.

The value will be decimal (two decimal digits are enough), it will always icrease (until it resets) and my main concern is to make it increase with variable speed, to give a more interesting visual effect. Meaning that if the (current value - previous value) is big the counter will speed up to "catch up".

I already have code that reads a value from a database and just prints it to a html div element every x seconds.
So i would like a suggestion on the counter increase algorithm.

Hope i made it clear... :)

Thanks in advance.

2
Contributors
2
Replies
35
Views
4 Years
Discussion Span
Last Post by ktsangop
0

I would like to implement a counter using ajax that will act like this:
The script will send a XMLHttpRequest every x seconds which will return a value from a mysql database.
Using the current and previous value retrieved from the server, the script will increase the counter, >in order to reach the new value in the x second interval between the server requests.

What code have you done so far? A little code provided would be helpful at least there's a direction.

0

Sorry i didn't post any code, i was in a hurry and wanted a suggestion because i was stuck.
In the end, i worked it over last night and managed to do it.

The key was to use setTimeout function with a variable timeout parameter. Timeout should be calculated on each call, using the previous and current value, and then passed to the next setTimeout call.

Thanks anyway.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.