-1

I need to write an ajax call which fires in every 5 seconds. I can write an ajax call as below. But I cant make it periodically. Please help me.

var set_delay = 5000,
click = function () {
    $.ajax({
        // ...
    })
    .done(function (response) {
        alert("");
    })
    .always(function () {
        // ...
    });
};
click();
Jochen van Wylick
  • 5,093
  • 4
  • 39
  • 61
Test
  • 45
  • 4
  • check this [question](http://stackoverflow.com/questions/5052543/how-to-fire-ajax-request-periodically) out, you should try to google before posting questions here... – stambikk Apr 22 '15 at 12:21

1 Answers1

3

You can use below code :

var set_delay = 5000,
click = function () {
    $.ajax({
    })
    .done(function (response) {
        alert("");
    })
    .always(function () {
        setTimeout(click, set_delay);
    });
};
click();
Ryan Ransford
  • 3,183
  • 27
  • 33
Hasanthi
  • 1,161
  • 1
  • 12
  • 26