Skip to content Skip to sidebar Skip to footer

Ajax Call In Array Loop, Call Next Only After Previous Complete

I have an array to upload data and I want them to send to server one by one. I want the previous one to complete before I send next one. Actually, after each response I want to dec

Solution 1:

You can use recursive function and put recursive call inside then:

(function loop() {
     if (packetCount<bulkUploadPackets.length) {
           d = d.then(save(bulkUploadPackets[packetCount]))
                .then(function(uploadResponse){
                      //I want to come here after first call complete before second call is fired and so on
                      packetCount++;
                      loop();
                 }); 
     }
})();

Post a Comment for "Ajax Call In Array Loop, Call Next Only After Previous Complete"