Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a javascript in which I will use setinterval to refresh my data every 5th minute mark and it works wonderfully. But one issue happened, when I pass in new parameter and the page refreshes at 5th minute mark, it used back the old parameter and returns me old data value.
Below are my codes:

JavaScript
if (_clearTimer == 0) {
                            _clearTimer = setInterval(function () {                            
                                var _date = new Date();
                                if ((_date.getMinutes() % 5) == 0) {
                                    MyMethod(param1);
                                }
                            }, 60000);
                        }

So in order to solve that, I have add in a new line of code which is clearInterval(_clearTimer) before the above codes as below:
JavaScript
clearInterval(_clearTimer);
    if (_clearTimer == 0) {
        _clearTimer = setInterval(function () {
            var _date = new Date();
            if ((_date.getMinutes() % 5) == 0) {
                MyMethod(param1);
            }
        }, 60000);
    }

But at the 5th minute mark, it used back the old parameter also. Any codes that I am missing?

What I have tried:

1. Using clearInterval to clear the previous setInterval.
Posted
Comments
Jamie888 9-Jun-16 21:33pm    
So I have found a aolution to it, may not be orthodox but can give it a shot. Just add a line of codes "_clearTimer = 0;" right after the clearInterval() in order to make the IF statement true and run the logic in it. That way will reset the setInterval() value and thus return the result that we want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900