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);
精彩评论