title: Javascript: Break out of a loop inside of the success function of an ajax request
body: <p>I need to send an $.ajax request and check the response HTML to see if it contains certain text. If it does infact, i want to execute a separate function and break the current loop so it doesn't keep making requests for the other items. </p>
  
  <p>I know i cannot break the loop inside the success function because it's in a scope of its own. Any solutions would be great.</p>
  
  <pre><code>    for(var i in list) {
  
        var item = list[i];
  
        $.ajax({
              type: 'POST',
              url: baseURL + '/ChangeItems/CheckAvailability',
              data: { 'newitem': item, 'purchaseItem': false },
              error: function(jqXHR, textStatus) { alert(textStatus); },
              dataType: 'text',
              success: function(data) { if(checkItem(data)) { buyItem(); break; } }
          });
     }
  </code></pre>