-1

How do I put 5 minutes delay after submit every 15 Query

so this is the javascript code I am using and it works fine.

But what I want is: I need to set a delay like of every 5 sec then execute the query, also after every 15 queries, needs to add a break for 5 minutes then continue the execution

<script>
$(function(){
    $.ajaxSetup ({
        cache: false
    });
    var ajax_load = "<img src='http://i.imgur.com/pKopwXp.gif' alt='loading...' />";

    // load() functions
    var loadUrl = "xxx.com/api.php?phone=xxxx&body=xxx";    
    $("#loadbasic").click(function(){
        $("#result").html(ajax_load).load(loadUrl);

    });
// end  
});

</script>
Gaurav joshi
  • 1,743
  • 1
  • 14
  • 28
Mail
  • 25
  • 7

1 Answers1

0

setInterval function returns an id which can be used to clear the call from the interval function, after passing the id to the clearInterval function. You can try something like this where I call a function after clicking a button every 5 seconds and keeping a counter variable on how many times the variable was incremented. If the counter is 5 then clear the interval and call the interval function after 10 seconds. Script code is something like this:

$(function(){
    $("#button").click(function() {
        intervalCall()
    })          
});

function intervalCall() {
  var counter = 0

  var intervalId = setInterval(function() {
      console.log("Hello")
      counter++
      if (counter == 5) {
      clearInterval(intervalId)
      setTimeout(intervalCall, 10000)
    }
  }, 5000)
}

JsFiddle code here.

Shababb Karim
  • 3,614
  • 1
  • 22
  • 35