Call jQuery Ajax Request Each X Minutes

Shahin picture Shahin · Feb 8, 2011 · Viewed 119.1k times · Source

How can I call an Ajax Request in a specific time Period? Should I use Timer Plugin or does jQuery have a plugin for this?

Answer

Ben picture Ben · Feb 8, 2011

You can use the built-in javascript setInterval.

var ajax_call = function() {
  //your jQuery ajax code
};

var interval = 1000 * 60 * X; // where X is your every X minutes

setInterval(ajax_call, interval);

or if you are the more terse type ...

setInterval(function() {
  //your jQuery ajax code
}, 1000 * 60 * X); // where X is your every X minutes