title: How to stop interval function
body: <p>I'm trying to stop with <code>return</code> syntax:</p>
  
  <pre><code>&lt;script&gt;
     $(document).ready(function() {
        setInterval(function() {
           var url = "../view/anychange.php";
           $.getJSON(url, function(data) {
            f(data.exists == 0){
          alert("0"); 
            } else {
          alert("1");
              return; 
            }
        });
      }, 5000);
  
  
     });
  &lt;/script&gt;
  </code></pre>
  
  <p>The function verifies every 5 seconds if there exists data in my table.</p>
  
  <p>I need to stop the function when <code>data.exists == 1</code> ( the <code>alert("1")</code> ).</p>