开发者

Calling Ajax repeatedly after specific time using jquery

Searched on jquery timer functions but i need a solution to call th开发者_JAVA百科e 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);
  }
});


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜