I need to create booklets with tickets in the database. The number of booklets depends upon what user enters in the textbox. One booklet can have 100 tickets. This creation of booklets/tickets take a long time, so i need to show progress to end user. For this purpose I put the ajax call to method in loop and increment the progress bar on success .
In the approach I'm trying to wait for the success method of first ajax call before making another. but this code never goes to the success method although code is working fine without loop for single call. I also noticed that loop runs indefinitely. How to fix it any idea?
Ajax call:
var number_of_booklets = 1;
var progress = 0;
var progressIncrement = 100 / number_of_booklets;
while (i < number_of_booklets) {
if (i == index) {
index++;
bCalled = true;
$.ajax
({
type: 'post',
url: "/Booklet/AddBooklet",
data: { 'booklet': booklet },
success: create_booklet_success,
failure: create_booklet_error,
timeout: 180000
});
}
}
success method:
function create_booklet_success(response)
{
i++;
progress = progress + progressIncrement;
$('#progressbarVal').html(Math.round(progress).toString()+"%");
$('.progress-bar').css('width', progress + '%').attr('aria-valuenow', progress);
if (progress == 100)
{
$('.content-wrapper').removeClass('whirl duo');
$("#progressbarModal").modal('hide');
}
//console.log(progress);
console.log(i)
}