title: Ending setInterval when ajax call is complete
body: <pre><code>    $.ajax({
                       
          url: vars.url,          
          type: &quot;post&quot;,          
          data: r,    
          async: true,        
          processData: vars.process,
          contentType: vars.contenttype,
          
          beforeSend: function(){
  
              if(vars.loadbar == 'true'){
  
                  setInterval(function () {
  
                      $.getJSON(domain + '/core/files/results.json',  function (data) {
  
                          console.log(data);  
  
                      })
                  
                  }, 1000);
              
              }
  
          },
          
          complete: function(){
  
              clearInterval();
  
          },
  
          succes: function(data){
              ..................
          }
  
      })   
  </code></pre>
  <p>So I am trying to end the infinite loop my code is spawning as soon as my ajax call is being done. It now phones pretty much every second to my file to get results, which i want to stop as soon as my ajax call is completed.</p>
  <p>I am not sure how to approach this, since if i assign a variable to the <code>setInterval</code> (being it in the function of the <code>beforeSend</code> itself, or outside of the AJAX call), it either wont see the variable, or my variable is empty. I think I am approaching this wrong. Can I check within the beforeSend if the AJAX call is complete to end the loop?</p>