title: jquery call ajax every second until call finishes / returns true
body: <p>I need to be able to call a function "getProgress" every second. This function does an ajax request and updates a progress bar. I need to be able to stop the call to this function when a call returned from ajax is "true".</p>
  
  <p>Html:</p>
  
  <pre><code>&lt;td class="checkbox"&gt;
  &lt;input type="checkbox" value="6" class="checkbox download" id="chk-6"&gt;
  &lt;div class="hide" id="prgbar-6"&gt;&lt;span class="progresslabel"&gt;&lt;/span&gt;&lt;/div&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>my function:</p>
  
  <pre><code>function getProgress(operationId) { // receives operationId
      $.post("@Url.Action("Status","Packages")", { operationId: operationId }, function (data) {
          if (data) {
              for (var key in data) {
                  if ($("#prgbar-" + key + "").size() != 0) {
                      var objPrg = $("#prgbar-" + key + "");
                      var objchk = $("#chk-" + key + "");
                      if (data[key]) {
                          objPrg.find("span").text("downloading...").css("color:#000000");
                          objchk.hide();
                          objPrg.removeClass("hide").show().progressbar({
                              value: 0
                          });
                          var value = Math.floor(parseInt(data[key]) * 100);
                          objPrg.progressbar("option", "value", value);
                          objPrg.find("span").text(value + "%");
                      } else {
  
                      }
                  }
              }
          }
      });
  }
  </code></pre>