D
D
Denis Ruchiev2017-01-09 20:06:43
JavaScript
Denis Ruchiev, 2017-01-09 20:06:43

Is it possible to draw progresbar while iterating over each?

in general, something like this codepen.io/DenisBardak/pen/VPvXpY
you need to change the state of the progress bar after processing each server response. How can this be implemented? with each it seems like nothing, after processing all requests it is drawn once. In general, after processing the response, start the next cycle, how can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ruchiev, 2017-01-09
@denis_bardak

$('#posting').click(function (){

     var items = $(".onepost");
     allpost = items.length;
     $('#accordion').hide();
     $('#loading').show();
     $('#progressbar').attr('aria-valuemax' , allpost);

     var myQueue = $({});

     $('.onepost').each(function(i,elem){
      var idpost = $(this).attr('data-idpost');
      myQueue.queue('stack', function(next) {
        $.ajax({
         type: 'POST',
         async: false,
         data: {post: idpost},
         success: function(data) {
           var procent = Math.round(i * 100 / allpost);
           $('#progressbar').attr('aria-valuenow' , i);
           $('#progressbar').css('width' , procent+'%');
         }
       });
        setTimeout(function() { next(); }, 10);
      });
    });

     myQueue.dequeue('stack');
   });

decided so

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question