Logo WMI
Site Overview
About Privacy Policy Terms Of Service Contact
HexoJS
hexo-adsense hexo-shortcodes hexo-seo
Games
Quiz The Legend Of Neverland Chimeraland Blacklist Player
Utilities
PHP Proxy Hunter Python Proxy Hunter Android Flashtool Utility
Site Overview
About Privacy Policy Terms Of Service Contact
HexoJS
hexo-adsense hexo-shortcodes hexo-seo
Games
Quiz The Legend Of Neverland Chimeraland Blacklist Player
Utilities
PHP Proxy Hunter Python Proxy Hunter Android Flashtool Utility

Search

[JS] How to delay ajax one by one in loop Bahasa indonesia: Bagaimana eksekusi ajax satu per satu di Loop

programming javascript , share

Bahasa indonesia: Bagaimana eksekusi ajax satu per satu di Loop

<div id="demo"></div>
<script>
/
* Define global variable
* @var {int} indexLoop global loop indexer
* @var {int} lastLoop global last iteration for global loop indexer from loop initializer
* @var {array} queueLoop global array to be processed from ajax
* @var {array} arrayLoop define array to be proccesed
*/

var indexLoop = 0,
lastLoop = 0,
queueLoop = [],
arrayLoop = ['apple', 'melon', 'watermelon', 'grapes'];

for (var i = 0; i < arrayLoop.length; i++) {
queueLoop.push(arrayLoop[i]);
if (i == arrayLoop.length - 1) {
lastLoop = i + 1;
ajaxLoop(function () {
var b = document.createElement('b');
b.innerHTML = 'Processing all item ' + indexLoop + ' of ' + lastLoop + ' succedeed<br/>';
document.getElementById('demo').appendChild(b);
});
}
}
/**
* Initialize global ajaxLoop function
* @param {function} lastFunction function to be executed on last iteration
*/
function ajaxLoop(lastFunction) {
if (indexLoop < lastLoop) {
$.ajax({
url: 'https://reqres.in/api/users?page=' + (indexLoop + 1),
beforeSend: function () {
var b = document.createElement('b');
b.innerHTML = 'Processing item ' + indexLoop + ' of ' + lastLoop + '<br/>';
document.getElementById('demo').appendChild(b);
},
success: function (response) {
var b = document.createElement('b');
b.innerHTML = 'Processed item success ' + this.url.split('=')[1] + ' of ' + lastLoop + '<br/>';
document.getElementById('demo').appendChild(b);
},
error: function () {
var b = document.createElement('b');
b.innerHTML = 'Processed item error ' + this.url.split('=')[1] + ' of ' + lastLoop + '<br/>';
document.getElementById('demo').appendChild(b);
},
complete: function () {
var b = document.createElement('b');
b.innerHTML = 'Processed item complete ' + this.url.split('=')[1] + ' of ' + lastLoop + '<br/>';
document.getElementById('demo').appendChild(b);
}
});

indexLoop++;
ajaxLoop();
if (indexLoop == queueLoop.length) {
if (typeof lastFunction == 'function') {
lastFunction();
/
reseting global indexer */
indexLoop = 0;
}
}
}
}
</script>

preview

Delay ajax in loop
Google passed proxies, updated at 2019-12-29
Javascript Debug Protector

  • preview

javascript share github github-actions-workflow matrix snippet yaml shell workflows tips & tricks bash android webview java minecraft vscode typescript nodejs javascript eslint jest npm prettier springboot webflux mocha esm react json typeerror regexp regular expression games seven knight bluestacks game control the legend of neverland life skill macros midi event recipes chimeraland attendant attendants skill pet guide monster fishing script Chimeraland scala map math unit adsense wordpress blogger blogging popular css seo php social media hosting html amp facebook tools vainglory codeigniter miscellaneous mysql movies linux/unix marketing strategies durango download software musics fonts regedit windows proxy share gradle kotlin cmd genshin impact ide xml templates themes powershell apache xampp recaptcha qfil firmware scripts hyperlink rollback linux python test coverage hexo random net ejs nunjucks hexo-shortcodes codepen markdown groovy proguard geckoview spring-boot mobile legends pyside6 chest location quest material recipe bug scenic-spot
© 2025 WMI™. All Rights Reserved.
  • About
  • Privacy Policy
  • Terms Of Service
  • Contact