Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
115
rated 0 times [  122] [ 7]  / answers: 1 / hits: 26995  / 15 Years ago, fri, august 7, 2009, 12:00:00

I have a ajax javascript method that pulls data from a page etc.



I want this process to run on a timed interval, say every minute.
But I don't want it to loop forever, so max out at 3 times.



What is the best way to implement this?


More From » jquery

 Answers
94

Like this:



var runCount = 0;    
function timerMethod() {
runCount++;
if(runCount > 3) clearInterval(timerId);

//...
}

var timerId = setInterval(timerMethod, 60000); //60,000 milliseconds

[#98964] Tuesday, August 4, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mireyag

Total Points: 73
Total Questions: 107
Total Answers: 85

Location: Ukraine
Member since Sun, Dec 13, 2020
3 Years ago
mireyag questions
Sun, Aug 15, 21, 00:00, 3 Years ago
Wed, Dec 16, 20, 00:00, 3 Years ago
Tue, Sep 1, 20, 00:00, 4 Years ago
Sun, Jul 5, 20, 00:00, 4 Years ago
;