title: PHP Laravel : TokenMismatchException in VerifyCsrfToken.php line 67
body: <p>Here the scenario is, I want to fetch some data from database and show it to user. While someone give some input and save it to database and I put a status with that which is always "<code>0</code>" until someone see it. So whenever a input has submitted user will see a pop up screen with that new data has inserted in another page. Here the problem is when ajax got some value with status "<code>0</code>" it shown it to screen but when it couldn't fetch any value ( <code>when all the status value is 1</code>)it shows error in console :  </p>
  
  <blockquote>
    <p><code>TokenMismatchException in VerifyCsrfToken.php line 67</code></p>
  </blockquote>
  
  <p>. </p>
  
  <p>How do I solve the issue , any possible suggestion please ?</p>
  
  <p>Here is the route:</p>
  
  <pre><code>Route::post('/unread',[
      'uses'=&gt;'ItemController@getUnread',
      'as'=&gt;'unread'
      ]);
  
  Route::post('/s_update',[
      'uses'=&gt;'ItemController@status_update',
      'as'=&gt;'s_update'
      ]);
  </code></pre>
  
  <p>Here is the controller :</p>
  
  <pre><code>public function getUnread()
              {
  
                  $items=DB::select(DB::raw("SELECT count(*) as total from items where status =0"));
                  // $data=mysql_fetch_assoc($items);
                   return Response::json($items);
              }       
  
              public function status_update()
              {
                  $items=DB::select(DB::raw("UPDATE items SET status=1 WHERE status=0"));
                  return Response::json($items);
              }
  </code></pre>
  
  <p>and here is the ajax call :</p>
  
  <pre><code>  &lt;script type="text/javascript"&gt;
                      setInterval(function(){ 
                              $(".container").load("list", function(){
                                  $.ajaxSetup({
                                    headers: {
                                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                                        }
                                   });
  
                                    $.ajax({
                                      type : "POST",
                                      url : "{{url('unread')}}",                                                             
                                       dataType : 'json',                             
                                      success : function(data) {
  
                                              $.each(data,function(index,subcatObj){                                                              
                                                  if(subcatObj.total != '0')
                                                  {
                                                      var yes = confirm('You have '+subcatObj.total+' new messages');
                                                              if(yes){
                                                                  status_update();
                                                              }
                                                  }
  
                                          });                             
                                      }, 
      });                                                                  
                          });          
                           }, 3000);  
  
                           function status_update(){
  
                             $.ajax({  
                                  url:"{{url('s_update')}}",  
                                  method:"POST",                                                                  
                             });  
                           }          
                  &lt;/script&gt;
  </code></pre>