0

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 ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Waseem Senjer
  • 1,026
  • 3
  • 14
  • 25

1 Answers1

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