title: Message: "CSRF token mismatch.", exception: "Symfony\Component\HttpKernel\Exception\HttpException",…}
body: <p>I am A PHP developer and currently moving towards Laravel framework as per my task I have to complete the realtime table using ajax but I am sticking with an error which is CSRF token mismatch error please help me to resolve the error I am posting shortcode only</p>
  <p><strong>JAVA Script</strong></p>
  <pre><code>&lt;script&gt;
  
   function getMessage() {
          $.ajax({
             //var data = {&quot;_token&quot;: $('#token').val()},
             type:'POST',
             url:'/getMsg',
             headers: {'XSRF-TOKEN': $('meta[name=&quot;_token&quot;]').attr('content')},
             success:function(data) {
                $(&quot;#msg&quot;).html(data.msg);
             }
             
          });
          
       }
      
    &lt;/script&gt;
  </code></pre>
  <p><strong>Route Path</strong></p>
  <pre><code>Route::post('/getMsg','CustomerSearchController@doAjaxTest');
  </code></pre>
  <p><strong>Controller code</strong></p>
  <pre><code>public function doAjaxTest(){
      $msg = &quot;&lt;b&gt;Message over ajax This test is Successful&lt;/b&gt;.&quot;;
      return response()-&gt;json(array('msg'=&gt; $msg), 200);
  }
  </code></pre>
  <p><em><strong>HTML CODE</strong></em></p>
  <pre><code>&lt;center&gt;
   
   &lt;input type = &quot;hidden&quot; name = &quot;_token&quot; value = '&lt;?php echo csrf_token(); ?&gt;'&gt;
   &lt;table&gt;
   &lt;tr&gt;
   
   &lt;td&gt;&lt;label&gt;Enter Place Name&lt;/label&gt;&lt;/td&gt;
   &lt;td&gt;&lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;placename&quot; name=&quot;placename&quot; placeholder=&quot;Name Of Place&quot;/&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
   &lt;td&gt;
   &lt;input type=&quot;submit&quot; value=&quot;Get Message&quot; onclick=&quot;getMessage()&quot; /&gt;
   &lt;/td&gt;
   &lt;/tr&gt;
   &lt;/table&gt;
  
   &lt;br&gt;
   &lt;!--
   &lt;div class=&quot;panel panel-default table-responsive&quot;&gt;
              &lt;div id=&quot;dataTag&quot;&gt;&lt;b&gt;All the Details according to department will be displayed&lt;/b&gt;&lt;/div&gt;
              
        &lt;/div&gt;
   --&gt;
   &lt;div id = 'msg'&gt;This message will be replaced using Ajax. 
       Click the button to replace the message.&lt;/div&gt;
    &lt;/center&gt;
  </code></pre>
  <p>I don't know why it is showing me CSRF token mismatch when headers contain tokens
  once solved i can have some realtime action please help out</p>