title: Javascript - AJAX request inside loops
body: <p>I'm using jQuery to send an AJAX request, retrieving data from a server.</p>
  
  <p>That data is then appended to an element. This should happen 5 times, but it will always happen randomly either 3, 4, or 5 times. Basically, sometimes the loop will skip the AJAX request, but the majority of the time it catches it. How do I make sure it completes the request five times every time? and what is the reason behind this random behavior of skipping AJAX request?(side note. I've checked the request errors, but it never alerted of a request failure)</p>
  
  <p><strong>Here's my JS:</strong></p>
  
  <pre><code>while (counter &lt; 6) {
      $.ajax({
          url:'http://whisperingforest.org/js/getQuote.php',
          async: false,
          dataType: 'jsonp',
          success:function(data){
              $('.quoteList').append('&lt;li&gt;' + data +'&lt;/li&gt;');
              totalQuotes++;
          }
      });
      counter++;
  }
  </code></pre>
  
  <p>P.s. this happens on a button press.</p>