Context
I update several sites with Ajax calls, one by one to conserve the server.
I made a recursive function that runs himself again when an Ajax call is completed.
Issue
The function is stopped after the first loop.
Any idea ?
Code
var updateSite = function (site) {
if (site.status == 'waiting for update') {
updateStatus(i, site, 'update in progress');
$.get(site.url)
.success(function () {
updateStatus(i, site, 'updated');
})
.error(function () {
updateStatus(i, site, 'not updated');
})
.complete(function () {
updateSite(allSites[i++]);
});
}
};
var i = 0;
updateSite(allSites[i]);
allSites.shift()instead ofallSites[i]you would not neediin the first place, but I guess you needifor further processing.