title: Trying to access Instagram API using jQuery
body: <p>I'm trying to use the Instagram API and I'm making AJAX requests in a do-while loop until the next_url is null. All I want this code to do is to fetch all the followers by making continuous requests until it's done. What is wrong in this code?</p>
  
  <p>When I remove the do-while loop it doesn't gives me an error, but as soon as a I use the AJAX request within a loop, it never stops. Clearly the <code>$next_url</code> string is not changing to the newly fetched <code>next_url</code> - why? What is wrong?</p>
  
  <pre><code>$(document).ready(function(e) {
          $('#fetch_followers').click(function(e) {
              var $next_url = 'https://api.instagram.com/v1/users/{user-id}/followed-by?access_token={access-token}&amp;count=100';
              var $access_token = '{access-token}';
              var $is_busy = false;
              var $count = 0;
              do {
                  while($is_busy) {}
                  $.ajax({
                      method: "GET",
                      url: $next_url,
                      dataType: "jsonp",
                      jsonp : "callback",
                      jsonpCallback: "jsonpcallback",
                      success: function(data) {
                          $is_busy = true;
                          $.each(data.data, function(i, item) {
                              $("#log").val($("#log").val() + item.id + '\n');
                          });
                          $("#log").val($("#log").val() + data.pagination.next_url + '\n');
                          $next_url = data.pagination.next_url;
                      },
                      error: function(jqXHR, textStatus, errorThrown) {
                          $is_busy = true;
                          //alert("Check you internet Connection");
                          $("#log").val($("#log").val() + 'Error\n');
                      },
                      complete: function() {
                          ++$count;
                          $is_busy = false;
                      }
                  });
              } while($next_url !== '' || $count &lt;= 50);
          });
      });
  </code></pre>
  
  <p>After I failed in my logic, I added the <code>$count</code> variable that can break the do-while loop, because the do-while loop was running infinitely. After adding it, it still runs infinitely, and I have no idea why.</p>