Want a javascript function to run every minute, but max 3 times

后端 未结 9 1042
终归单人心
终归单人心 2020-12-28 17:43

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 forev

9条回答
  •  难免孤独
    2020-12-28 18:05

    You can use setInterval() and then inside the called function keep a count of how many times you've run the function and then clearInterval().

    Or you can use setTimeout() and then inside the called function call setTimeout() again until you've done it 3 times.

提交回复
热议问题