title: AJAX Request in CodeIgniter Application Failing After Inactivity
body: <p>The application I am working on is built in CodeIgniter, and the content is always loaded via ajax into the main content div.</p>
  
  <p>This works without fail normally, apart from after the user has been inactive for a short while.</p>
  
  <p>We haven't completely narrowed down the inactivity time required for the request to fail, but it's around 40 minutes or more of inactivity.</p>
  
  <p>I've tried logging details to the console in the error callback of the AJAX request, but nothing is logged.</p>
  
  <p>I'm thinking that it's related to a session expiry but I can't be sure. I know when using CodeIgniter, there are two sessions which are created automatically (PHPSESSID, and ci_session) so my instinct is that it has something to do with these, or one of them, expiring?</p>
  
  <p>When the request fails the headers, preview, response and cookies tab on chrome's developer tools show nothing.</p>
  
  <p>If anyone has experienced this before, or has any ideas what may be causing the problem, I'd appreciate the input.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Below is the AJAX request which is experiencing the above problem.</p>
  
  <p>All links within my application use this loadPage function instead of a standard redirect.</p>
  
  <pre><code>function loadPage(href, type, clickElem, changeHash) {
      if(ajax_loading == true) { return false; }
      ajax_loading = true;
      $('#recording_area').slideUp('slow');
      if(typeof queue_countdown !== 'undefined') { clearInterval(queue_countdown); }
      if(type == 'sidenav') {
          $('#sidenav_accordion .accordion-heading a').removeClass('on');
          $('#sidenav_accordion .accordion-inner a').removeClass('on');
          $(clickElem).parents('.accordion-group').find('.accordion-heading a').addClass('on');
          $(clickElem).addClass('on');
      } else {
          page_requested = href.replace(/^\/([^\/]*).*$/, '$1');
          if(!page_requested) { page_requested = 'dashboard'; }
          nav_elem = $('.sidenav a[href="/' + page_requested + '"]');
          if(nav_elem.html() != null) {
              nav_elem_group = nav_elem.parents().eq(2).children().first().find('a');
              if(!nav_elem_group.hasClass('on')) {
                  if(!nav_elem.parents().eq(2).children().first().next().hasClass('in')) { nav_elem_group.click(); }
                  $('.sidenav .on').removeClass('on');
                  nav_elem.addClass('on');
                  nav_elem_group.addClass('on');
              }
          }
      }
      current_ajax_request = $.ajax({
          type: 'GET',
          url: href,
          dataType: 'html',
          cache: true,
          beforeSend: function() {
          },
          success: function(data){
              $('#map-canvas').remove();
              $('.content_wrapper script').each(function(){
                  $(this).remove();
              });
              $('#gbox_Customers').remove();
              if ($.browser.msie  &amp;&amp; parseInt($.browser.version, 10) === 7) {
                  $('.content_wrapper').hide().html(data).show();
                  $('#content_overlay').hide();
              } else {
                  $('.content_wrapper').fadeOut().html(data).hide().fadeIn();
                  $('#content_overlay').fadeOut();
              }
              $('.queue_loading').hide();
              console.log('success ended');
          },
          error: function(xhr,status,error) {
              /*
               * The below console logs do not fire when the problem is occuring.
               */
              console.log('ERROR');
              console.log('xhr: ' + xhr);
              console.log('status: ' + status);
              console.log('error: ' + error);
  
              $('#map-canvas').remove();
              $.get('inc.404.php', function(data) {
                  if($.browser.msie  &amp;&amp; parseInt($.browser.version, 10) === 7) {
                      $('.content_wrapper').hide().html(data).show();
                  } else {
                      $('.content_wrapper').fadeOut().html(data).hide().fadeIn();
                  }
              });
              if ($.browser.msie  &amp;&amp; parseInt($.browser.version, 10) === 7) {
                  $('#content_overlay').hide();
              } else {
                  $('#content_overlay').fadeOut();
              }
              $('.queue_loading').hide();
          },
          complete: function(data) {
              console.log(data);
              ajax_loading = false;
              set_tooltips();
          }
      });
      if(changeHash != false) {
          window.location.hash = "!" + href;
      }
  }
  </code></pre>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>After putting several console log's through the function, to see at which point it breaks. The problem decided to disappear. For what reason would adding console logs to the function prevent this issue from occurring?</p>
  
  <p>I'm currently waiting an hour or so to re-test it without the console logs to make sure it isn't a red herring.</p>
  
  <p><strong>Edit 3:</strong></p>
  
  <p>After putting in console logs in the error callback of the AJAX request, it seems that the error callback is not firing. Not quite sure where to look now - as if it was a success, it would surely return the content.</p>