Skip to content

Instantly share code, notes, and snippets.

@t9toqwerty
Last active November 2, 2016 12:58
Show Gist options
  • Save t9toqwerty/69bf3ec6dc4b33ad4f22d3e2912f4838 to your computer and use it in GitHub Desktop.
Save t9toqwerty/69bf3ec6dc4b33ad4f22d3e2912f4838 to your computer and use it in GitHub Desktop.
Execute Loop with delay in Javascript
$(document).ready(function () {
$("#submit").on('click', function () {
var links = $('#links').val().split(/\n/);
var apiCount = 0;
var i=0;
processNextAjax();
function processNextAjax() {
var temp_links = links.slice(i, i + 9);
console.log(temp_links);
var data = fetchData(temp_links, apiCount);
apiCount++;
if (i > links.length) {
return;
}
i = i + 9;
setTimeout(processNextAjax, 4000);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment