title: Codeigniter session bugging out with ajax calls
body: <p>My CodeIgniter app uses the session library and saves data to the DB.</p>
  
  <p>I've been having some problems where blank sessions are created after a certain ajax call.</p>
  
  <p>Upon investigating, it seems that there were 2 simultaneous functions calls that fired off that require a session validation. One would fail and the other would be fine.</p>
  
  <p>I was able to fix this by not having them fire off simultaneously. But I still don't understand the REASON why it fails. Does it have to do with one call updating the user cookie and the 2nd call invalidating? Or maybe when reading the DB it dies somehow?</p>
  
  <p>I looked over the Session core class a bit and have not found any clues to the cause.</p>
  
  <p>If any one had the same problem before I would appreciate any advice on how to debug or what the cause is.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: </p>
  
  <p>I originally said there was a 408 status return. That was an unrelated case.</p>
  
  <p>This is the function that fires off MyVar.refresh() in parallel:</p>
  
  <pre><code>function (event)
  {
      var self$ = this.a$;
      var uid  = this.b$.val();
      var tid  = this.c$.val();
      var jqxhr = $.post('/controller1/index',{'uid':uid,'tid':tid,'action':true},function(re)
      {
          if(re.message != 'success')
          {
              MyVar.alert('&lt;span class="msg_error sprite"&gt;&lt;/span&gt;' + re.error);
              MyVar.refresh();
          } 
  
      },'json');
      MyVar.refresh();
      return stopDefault(event);
  };
  </code></pre>
  
  <p><strong>POSSIBLE SOLUTIONS:</strong></p>
  
  <p>Found this: <a href="http://codeigniter.com/forums/viewthread/102456/" rel="noreferrer">http://codeigniter.com/forums/viewthread/102456/</a></p>
  
  <p>Apparently it doesn't play well with ajax. One solution is to disallow session update if it is an ajax call; only problem is that our site is mostly built with ajax..</p>
  
  <p>Also, just lowered the sess_time_to_update to something very frequent and ajax was doing fine. Also did a browser refresh and it did not timeout. Not sure why if the session ID has already changed upon an ajax call and browser cookies were never updated.</p>