Skip to content

Instantly share code, notes, and snippets.

@ksomemo
Created June 15, 2013 07:08
Show Gist options
  • Save ksomemo/5787223 to your computer and use it in GitHub Desktop.
Save ksomemo/5787223 to your computer and use it in GitHub Desktop.
jQueryのajaxによるポーリング
var totalCount = 0;
var interval = 30000;
var delay = 3500;
var eachInterval = 1500;
function ajaxPolling(){
$.ajax({
url: "target url"
success:function(data){
var eachCount = 0;
$(data).find('css selector')
.not(':contains(exclude target css selector)')
.find('real target selector').each(function(){
setTimeout(function(parameter){
return function(){
$.ajax({
url: "Construction of the url with parameter"
});
console.log(new Date() + ':' + (++totalCount));
}
}(this.parameter), delay + eachInterval * ++eachCount);
});
setTimeout(ajaxPolling, interval);
}});
}
ajaxPolling();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment