What is wrong with this setInterval() code of javascript?
<p>Hi I am working on an application in Django. I have multiple threads running and I need to check the status of the threads periodically. So I used <code>setInterval()</code> but I want to stop it when I have exception in thread. But it is not stopping and keeps on calling the URL. Here is my code:</p>

<pre><code>function checkThreadsStatus(){
   var g_progress_intv = setInterval(function() {
       $.post("some_url", function(json_response) {
           var jsonObj = eval("(" + (json_response) + ")");
           if (jsonObj.exceptionOccur){
               clearInterval(g_progress_intv);
               g_progress_intv = 0;
           }
           else{
               //do some stuff
           }
           });
    }, 2000);
 }
</code></pre>

<p><code>jsonObj.exceptionOccur</code> is a <code>boolean</code> variable. But when it is <code>True</code> <code>setInterval()</code> does not <code>Stop</code>.</p>
