title: setInterval alternative
body: <p>In my app I am polling the webserver for messages every second and displaying them in the frontend.
  I use setInterval to achieve this. However as long as the user stays on that page the client keeps polling the server with requests even if there is no data. The server does give an indication when no more messages are being generated by setting a variable.
  I thought of using this variable to clearInterval and stop the timer but that didn't work. What else can I use in this situation?
  I am using jquery and django. Here is my code:</p>
  
  <pre>
  jquery:
   var refresh = setInterval(
          function ()
              {
                  var toLoad = '/myMonitor'+' #content';             
                  $('#content').load(toLoad).show();
  
              }, 1000); // refresh every 1000 milliseconds
      });
  
  html:
  div id=content is here 
  </pre>
  
  <p>I can access the django variable for completion in html with each refresh. How can I set clearInterval if at all ?</p>
  
  <p>Note: stack overflow does not let me put is &amp;gt &amp;lt so html is incomplete</p>
  
  <p>Thanks</p>
  
  <p><strong>Updated 03/16/2010</strong>
  I must be doing something wrong. But cannot figure it out. Here is my script with clearTimer and it does not work.</p>
  
  <pre>
  
  var timer = null;
  $(function(){
          if ("{{status}}" == "False")
          {
             clearInterval(timer);
          }
          else
          {
              timer = setInterval(
                  function(){
                      var toLoad = '/myMonitor'+' #content';  
                      $('#content').load(toLoad).show();} 
                      ,1000); // refresh every 1000 milliseconds
          }
      });
  
  </pre>
  
  <p>status is a boolean set in "views.py" (Django).
  Thanks a bunch.</p>