oldrock
oldrock

Reputation: 871

Calling Ajax repeatedly after specific time using jquery

Searched on jquery timer functions but i need a solution to call the below ajax function every 5 minutes using jquery..

    $.ajax({
  type: 'POST',
  url: '<?php echo base_url().'index.php/score-refresh/scorecard';?>',
  success: function(html){
    $('.score_news').append(html);
  }
});

Upvotes: 1

Views: 4173

Answers (1)

Martin Jespersen
Martin Jespersen

Reputation: 26183

You can do it using a setInterval call like this

var timer, delay = 300000; //5 minutes counted in milliseconds.

timer = setInterval(function(){
    $.ajax({
      type: 'POST',
      url: '<?php echo base_url().'index.php/score-refresh/scorecard';?>',
      success: function(html){
        $('.score_news').append(html);
      }
    });
}, delay);

if you need it to stop at some point call

clearInterval(timer);

Upvotes: 7

Related Questions