Search code examples
ajaxjquerytimer

Call jQuery Ajax Request Each X Minutes


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


Solution

  • 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