-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,303
  • 4
  • 42
  • 64
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,224
  • 28
  • 35
Hasanthi
  • 1,251
  • 3
  • 14
  • 30