Reputation: 21854
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.
The function is stopped after the first loop.
Any idea ?
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]);
Upvotes: 2
Views: 155
Reputation: 22458
Change complete function as below:
function () {
updateSite(allSites[++i]);
}
Upvotes: 5
Reputation: 49114
Any error messages?
Perhaps the var updateSite
is not yet defined when the anonymous function you're using for complete is defined.
Try this:
var updateSite;
updateSite = function (site) {
if (site.status == 'waiting for update') {
updateStatus(i, site, 'update in progress');
.... // everything else the same...
Upvotes: 0