Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jquery ajax / bs progress bar

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
Given the code

Code:
$.ajax({
   url: "_apiListCarriers.php",
   type: "POST",
   data: "a=getList",
   success: function(response) {
      $('#processProgressBar').css('display','block');
      var objs = JSON.parse(response);
      var n=getObjectCount(objs);
      var count = 0;
      while (objs[count]) {
      var pct = (count / n) * 100;
      var data = objs[count];
      $.ajax({
      url: "primusRateOne.php",
      type: "POST",
      timeout: 30000,
      data: "cc="+data.rateAs+'&seq='+seq+'&cid='+data.carrierID+"&pfqual="+data.PFQUAL+"&refbgID="+data.refbgID+"&formData="+formData,
      success: function(response) {
      $('#progressBarRole').attr('aria-valuenow',''+Math.ceil(pct)+'');
      $(".progress-bar").css("width", Math.ceil(pct) + "%").text(Math.ceil(pct) + " %");
      $('#barPCT').html(''+Math.ceil(pct)+"%");
      if(response === 'ERROR') {
         $( "#"+data.refbgID+"" ).remove();
      } else {
         $("#responseTable").append(response);
      }
      },
                       error: function(response) {
                            $('#progressBarRole').attr('aria-valuenow',''+Math.ceil(pct)+'');
                            $(".progress-bar").css("width", Math.ceil(pct) + "%").text(Math.ceil(pct) + " %");
                            $('#barPCT').html(''+Math.ceil(pct)+"%");
                       }
                   });
                   window.scrollTo(x, y); y+=30;
                   count++; seq++;
               }  // while
           }
        });
I am looking to answer the following questions

(a) Why do I reach 100% and responses keep appending for 10 seconds?
(b) if I move count++; within the success: or error: blocks, the script hangs and causes browser to halt; why is this?



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top