Created
June 15, 2013 07:08
-
-
Save ksomemo/5787223 to your computer and use it in GitHub Desktop.
jQueryのajaxによるポーリング
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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