title: How to continiously check how many files are in a folder with AJAX and PHP
body: <p>So right now I am continiously sending xmlhttprequests with GET to a PHP script that is giving me back the amount of files in a folder.</p>
  
  <p>I repeated the javascript function with a <code>setInterval()</code> and it is working really fine but I want the <code>setInteral()</code> to stop as soon as I get back a certain number from my PHP script.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    &lt;script&gt;
      function checkmedia(url,format) {
        var format1 = format;
          var xhttp = new XMLHttpRequest();
          xhttp.onreadystatechange = function() {
              if (this.readyState == 4 &amp;&amp; this.status == 200) {
                progress = this.responseText;
                  document.getElementById("progress").innerHTML =
                      this.responseText;
              }
          };
          xhttp.open("GET", 'checkfilecount.php?userurl='+url+'&amp;act=run&amp;format-option=' + format, true);
          xhttp.send();
          if(progress != "100") {
          var media_progress = setInterval(checkmedia.bind(null,url,format1), 10000);
        }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>As I am calling this XMLHttpRequest continiously and several times (for a table) I am getting a memory leak.</p>
  
  <p>Any kind of help is welcome. Thanks.</p>