title: Tracking multiple jquery ajax API requests with progress bar
body: <p>I have an increment that takes the ids and add them to url to make multiple ajax requests.
  <br><strong>js:</strong></p>
  <pre><code>for (x = 1; x &lt;= val['id_count']; x++) {
   $.ajax({
      url: baseUrl + x,
      dataType: &quot;json&quot;,
      success: function(results, status, xhr) {
     },
      error: function(xhr, status, error) {
      $(&quot;#message&quot;).html(&quot;data: &quot; + status + &quot; &quot; + error)
     }
   })
  }
  </code></pre>
  <p><br><strong>HTML</strong></p>
  <pre><code>&lt;div class=&quot;progress&quot;&gt;
      &lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 0%&quot; aria-valuenow=&quot;25&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>what i trying to do here is to count the ids (urls) and show the progress of requests is progress bar and see what percent is complete and what percent is left. also how many total ids is there and how many request is completed from total.</p>
  <p>in the other hand this is what i want to do <strong>for example:</strong>
  <a href="https://i.stack.imgur.com/3CRKn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3CRKn.png" alt="enter image description here" /></a></p>
  <p><strong>what i have done so far:</strong></p>
  <pre><code>for (x = 1; x &lt;= val['id_count']; x++) {
   totalIDs = 0;
   totalIDs = x.length;
   $.ajax({
      url: baseUrl + x,
      dataType: &quot;json&quot;,
      xhr: function() {
        var xhr = new window.XMLHttpRequest();
        xhr.onreadystatechange = function() {
        var progress = x / totalIDs * 100;
        $(&quot;.progress-bar&quot;).css({
            &quot;width&quot;: progress + &quot;%&quot;
          });
        }
       return xhr;
      },
      success: function(results, status, xhr) {
      },
      error: function(xhr, status, error) {
      $(&quot;#message&quot;).html(&quot;data: &quot; + status + &quot; &quot; + error)
     }
   })
  }
  </code></pre>
  <p>ps: new to this</p>