title: jquery ajax call not asynchronous
body: <p>I am fresh to jQuery's implementation of it's AJAX methods.</p>
  
  <p>I have a simple setup that accesses two different pages, one which takes 10 seconds to complete (I have a timer set on it) and one which checks on the status of the first page.</p>
  
  <p>The two functions are <code>progressCheck()</code> which requests its page every second with the latest status and <code>beginLogin()</code> which takes 10 seconds to load.  I set a value in the user object on the server that both pages access through symfony 1.4.  </p>
  
  <p>The issue is that the <code>progressCheck()</code> works correctly until I click <code>beginLogin()</code>, then no changes are made until <code>beginLogin()</code> finishes.  I have both functions setup to run asynchronously.  I know it must be something simple to figure out, but I am at a loss.</p>
  
  <p>I ran Firebug - Net while running this page and the result is:
  <img src="https://i.stack.imgur.com/O5OsE.png" alt="AJAX Net calls"></p>
  
  <p>A number of the <code>progressCheck()</code> are called during the wait period for the 10 second call, but Net says they ran in ~200 ms without any wait time.  </p>
  
  <p>Any ideas?</p>
  
  <p>Code below:</p>
  
  <pre><code>&lt;button onclick="beginLogin();"&gt;Begin Login&lt;/button&gt; 
  &lt;button onclick="progressCheck();"&gt;Check Progress&lt;/button&gt; 
  &lt;button onclick="clearCheck();"&gt;Clear Check&lt;/button&gt;
  &lt;br/&gt;
  &lt;div id="result_div"&gt;
  
  &lt;/div&gt;
  &lt;div id="progress_div"&gt;
  
  &lt;/div&gt;
  
  &lt;style type="text/css"&gt;
      #progress_div
      {
          width:              800px;
          height:             200px;
          border:             1px solid #CCCCCC;
          overflow:           scroll;
          background-color:   #AAEEFF;
      }
  
      #result_div
      {
          width:              800px;
          height:             300px;
          border:             1px solid #CCCCCC;
          overflow:           scroll;
          background-color:   #FFEEAA;
      }
  &lt;/style&gt;
  &lt;script type="text/javascript"&gt;
      function beginLogin()
      {
          try
          {
              var login_url   = "http://example.com/home/loginScript";
              $.ajax({
                  url:        login_url,
                  success:    function(data){
                      $("#result_div").append('&lt;pre&gt;'+data+'&lt;/pre&gt;&lt;hr/&gt;');
                      alert("finished");
                  }
              });
          }
          catch(e)
          {
              alert("There was an error beginning the login: " + e);
              return false;
          }
          return true;
      }
  
      function progressCheck()
      {
          try
          {
              var check_url   = "http://example.com/home/checkLoginProgress";
              $.ajax({
                  url:        check_url,
                  success:    function(data){
                      $("#progress_div").append('&lt;pre&gt;'+data+'&lt;/pre&gt;&lt;hr/&gt;');
                  }
              });
          }
          catch(e)
          {
              alert("There was an error checking the progress: " + e);
              return false;
          }
          check_id = setTimeout('progressCheck()', 1000);
          return true;
      }
  
      // set progress checking function to call every second
      var check_id = setTimeout('progressCheck()', 1000);
  
      function clearCheck()
      {
          try
          {
              clearTimeout(check_id);
          }
          catch(e)
          {
              alert("There was an error clearing the check: " + e);
              return false;
          }
          return true;
      }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong>
  Here are the two PHP functions that returns the data for the two page calls</p>
  
  <pre><code>define('DEBUG', true);
  
  public function executeCheckLoginProgress(sfWebRequest $request)
  {
      if($this-&gt;getUser()-&gt;hasAttribute('login_script', 'sfGuardSecurityUser'))
          $this-&gt;login_progress = $this-&gt;getUser()-&gt;getAttribute('login_script', -1, 'sfGuardSecurityUser');
      else
          $this-&gt;login_progress = '[undefined]';
      $conn = $this-&gt;connectTestDb();
      $query  = sprintf("SELECT * FROM company_type WHERE id = 1;");
      $result = mysql_query($query, $conn);
      $this-&gt;login_progress = mysql_result($result, 0, 'name');
      if($request-&gt;isXmlHttpRequest())
      {   // this is an ajax all, only return value
          $this-&gt;getResponse()-&gt;setHttpHeader("Content-type", "text/plain");
          $this-&gt;getResponse()-&gt;setContent($this-&gt;login_progress);
          return sfView::NONE;
      }
  }
  
  public function executeLoginScript(sfWebRequest $request)
  {
      $user = $this-&gt;getUser();
      if(!$user-&gt;hasAttribute('login_script', 'sfGuardSecurityUser'))
          $user-&gt;setAttribute('login_script', 0, 'sfGuardSecurityUser');
  
      $this-&gt;login_value      = $user-&gt;getAttribute('login_script', 0, 'sfGuardSecurityUser');
  
      $conn = $this-&gt;connectTestDb();
      $query  = sprintf("SELECT * FROM company_type WHERE id = 1;");
      $result = mysql_query($query, $conn);
      $this-&gt;login_value = mysql_result($result, 0, 'name');
  
      $result = $user-&gt;assignAccessLevelIds();
      if($result === true)
      {
          $this-&gt;login_value += 5;
          $user-&gt;setAttribute('login_script', $this-&gt;login_value, 'sfGuardSecurityUser');
          $query  = sprintf("UPDATE company_type SET `name` = '%s' WHERE id = 1;", mysql_real_escape_string($this-&gt;login_value));
          $result = mysql_query($query, $conn);
          $this-&gt;login_progress = mysql_result($result, 0, 'name');
      }
      else
      {
          DataMan::logRawMessage('Unable to set access level user ['.$user-&gt;getAttribute('user_id', null, 'sfGuardSecurityUser'), sfLogger::WARNING);
      }
      // just for testing sleep!
      if(DEBUG === true)
          sleep(5);
  
      $result = $user-&gt;assignCompanyIds();
      if($result === true)
      {
          $this-&gt;login_value += 5;
          $user-&gt;setAttribute('login_script', $this-&gt;login_value, 'sfGuardSecurityUser');
          $query  = sprintf("UPDATE company_type SET `name` = '%s' WHERE id = 1;", mysql_real_escape_string($this-&gt;login_value));
          $result = mysql_query($query, $conn);
          $this-&gt;login_progress = mysql_result($result, 0, 'name');
      }
      else 
      {
          DataMan::logRawMessage('Unable to set company ids user ['.$user-&gt;getAttribute('user_id', null, 'sfGuardSecurityUser').'] '.__LINE__, sfLogger::WARNING);
      }
      // just for testing sleep!
      if(DEBUG === true)
          sleep(5);
  
  
  
  }
  </code></pre>