title: Laravel and AJAX sporadic 401 errors in a poller
body: <p>I’m coding an auction website in Laravel 5.0 that simulates realtime updates by using an AJAX poller that is executed every 5 seconds. The problem is that my server returns sporadic HTTP 401 status.</p>
  
  <p>My route is build like this:</p>
  
  <pre><code>Route::post(auction/live/update, 'AuctionController@ajaxSendUpdate');
  </code></pre>
  
  <p>My controller is like this:</p>
  
  <pre><code>public function ajaxSendUpdate() {
      // Business logic: queries database, couple of Ifs, etc…
      $data = array('success' =&gt; true, 'otherStuff' =&gt; $myData);
      return Response::json($data);
  }
  </code></pre>
  
  <p>Finally my poller is setup like this:</p>
  
  <pre><code>// a bit of HTML
  function getAuctionUpdate() {
      setTimeout(function () {
      $.ajax({
          type: "POST",
          url: "{!! url('auction/live/update')!!}",
              dataType: 'json',
              data: {
                  auctionID: $('#auctionID').val()
              },
              success: function (data) {
                  if (data['success']) {
                      // Updates some labels, etc.
                     getAuctionUpdate(); // Rearms itself
                  }
              }
      } }); // Not sure if all brackets are correct in this snippet but they are 100% on real code
  }, 5000);
  </code></pre>
  
  <p>This code runs fine about 95% of times. However it can break with 2 different outcomes:</p>
  
  <p>1)  Server responds error 401 after some time and never recovers. In this scenario we need to login again. After login, everything goes well and this outcome never occurs again.</p>
  
  <p>2)  Server responds with sporadic 401 but recovers in the next (or after a few) polling requests.</p>
  
  <p>I’m using Laravel 5.0 and an up-to-date version of Xampp on Windows. The error is easily reproduced with WAMP on Windows. Not tested in Linux nor OSX. I've read <a href="https://stackoverflow.com/questions/32433062/many-time-401-unauthorized-on-ajax-requests">this</a> and <a href="https://stackoverflow.com/questions/29899331/401-unauthorized-delete-request-to-restful-api-in-laravel-via-ajax">this</a> and assorted threads in laracasts.com and other forums but I am unable to solve the problem...</p>