I want to ping the server every 2 minutes using jQuery. I thought about an open loop with setTimeout function but I think this would crush the browser - any suggestions ?
Asked
Active
Viewed 2,139 times
1 Answers
4
Do not use setTimeout() for this type of action, rather use setInterval().
var intervalId = setInterval(function() {
/* Do your magic */
}, 2000);
To clear your interval, simply clearInterval(intervalId)
, when you wish to stop the ping:ing.

Björn
- 29,019
- 9
- 65
- 81