如何停止区间函数

Jho*_*val 0 javascript return function

我试图停止return语法:

<script>
   $(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);


   });
</script>
Run Code Online (Sandbox Code Playgroud)

该函数每 5 秒验证一次表中是否存在数据。

我需要在data.exists == 1( alert("1"))时停止该功能。

Can*_*ide 5

<script>
   $(document).ready(function() {
      var id;
      id = setInterval(function() {
         var idRefCopy = id; // You need this otherwise you'll get a reference exception
         var url = "../view/anychange.php";
         $.getJSON(url, function(data) {
         if(data.exists == 0){
           alert("0"); 
         } else {
           alert("1");
           clearInterval(idRefCopy);
           return; 
         }
      });
    }, 5000);
   });
</script>
Run Code Online (Sandbox Code Playgroud)