title: Set a delay in a repeating jQuery / Ajax function
body: <p>I am trying to add a delay to a repeatable query.</p>
  
  <p>I found out that .delay is not the one to use here. Instead, I should go with setInterval or setTimeout. I tried both, without any luck.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;?php 
  include("includes/dbconf.php");
  
  $strSQL = mysql_query("SELECT workerID FROM workers ORDER BY workerID ASC");
  while($row = mysql_fetch_assoc($strSQL)) {
  ?&gt;
  &lt;script id="source" language="javascript" type="text/javascript"&gt;
  
    $(setInterval(function ()
    {
      $.ajax({                                      
        cache: false,
        url: 'ajax2.php',        
        data: "workerID=&lt;?=$row['workerID'];?&gt;",
        dataType: 'json',    
        success: function(data)
        {
          var id = data[0];              //get id
          var vname = data[1];           //get name
          //--------------------------------------------------------------------
          // 3) Update html content
          //--------------------------------------------------------------------
          $('#output').html("&lt;b&gt;id: &lt;/b&gt;"+id+"&lt;b&gt; name: &lt;/b&gt;"+vname);
        } 
      });
    }),800); 
  
    &lt;/script&gt;
  &lt;?php
  }
  ?&gt;
  &lt;div id="output"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The code works fine, it outputs the result as asked. It's just loads without the delay. The timout and / or interval doesn't seem to work. </p>
  
  <p>Anybody knows what I am doing wrong?</p>