title: Ajax Post not Working in laravel 5.1
body: <p>I am trying to post data using ajax in laravel but it seems to be not working. I have followed following is my code</p>
  
  <p>login.blade.php</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;meta name="csrf_token" content="{{ csrf_token() }}" /&gt;
  
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"&gt;
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt; 
  &lt;style type="text/css"&gt;
  
  &lt;/style&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
    $('.send-btn').click(function(){   
    console.log($('input[name=email]').val());
      $.ajax({
        url: 'login',
        type: "post",
        data: {'email':$('input[name=email]').val(), '_token': $('input[name=_token]').val()},
        success: function(data){
        console.log($('input[name=email]').val());
          alert(data);
        }
      });      
    }); 
  
  
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="secure"&gt;Secure Login form&lt;/div&gt;
  {!! Form::open(array('url'=&gt;'account/login','method'=&gt;'POST', 'id'=&gt;'myform')) !!}
  &lt;div class="control-group"&gt;
    &lt;div class="controls"&gt;
       {!! Form::text('email','',array('id'=&gt;'','class'=&gt;'form-control span6','placeholder' =&gt; 'Email')) !!}
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="control-group"&gt;
    &lt;div class="controls"&gt;
  
    &lt;/div&gt;
  &lt;/div&gt;
  {!! Form::button('Login', array('class'=&gt;'send-btn')) !!}
  {!! Form::close() !!}
  &lt;/body&gt;
  &lt;/html&gt;                                     
  </code></pre>
  
  <p>and route.php</p>
  
  <pre><code>Route::get('account/login', function() {
    return View::make('login');
  });
  Route::post('account/login', 'AccountController@login');
  </code></pre>
  
  <p>and in controller</p>
  
  <pre><code> public function login() {
      // Getting all post data
      if(!Request::ajax()) {
        $data = Input::all();
        print_r($data);
      }
  
      }
  </code></pre>
  
  <p>Whenever I try to submit form not working. I tried using alert in onclick jquery but it shows alert message. Can anyone tell why it's not working?</p>
  
  <p>Note: This question already asked but not found any answer useful for me</p>
  
  <p><a href="https://stackoverflow.com/questions/31955974/laravel-5-1-ajax-not-working">Laravel 5.1 ajax not working?</a></p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function(){
    $('.send-btn').click(function(){   
    console.log($('input[name=email]').val());
      $.ajax({
        url: 'login',
        type: "post",
  
        data: {'email':$('input[name=email]').val(), '_token': $('input[name=_token]').val(),'_method': 'POST'},
        success: function(data){
        console.log($('input[name=email]').val());
          alert(data);
        }
      });      
    }); 
  
  
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>In console security i get following error </p>
  
  <pre><code> [HTTP/1.0 500 Internal Server Error 115ms]
  
  
  Update 2
  
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;meta name="csrf_token" content="{{ csrf_token() }}"&gt;
  
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"&gt;
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt; 
  &lt;style type="text/css"&gt;
  
  &lt;/style&gt;
  
  &lt;script&gt;
  $(document).ready(function() {
      $('#frm').on('submit', function (e) {
      alert();
          e.preventDefault();
          var title = $('#title').val();
          var body = $('#body').val();
          var published_at = $('#published_at').val();
          $.ajax({
              type: "POST",
              url: 'http://localhost/demo/public/articles/articles',
              headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          },
              dataType: 'JSON',
              data: {title: title, body: body, published_at: published_at},
              success: function( data ) {
                  $("#ajaxResponse").append(data.msg);
                  alert(data);
              }
          });
      });
      });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  {!! Form::open(['url' =&gt; 'articles', 'id' =&gt; 'frm']) !!}
      &lt;p&gt;
          {!! Form::label('title', 'Title:') !!}
          {!! Form::text('title') !!}
      &lt;/p&gt;
  
      &lt;p&gt;
          {!! Form::label('body', 'Body:') !!}
          {!! Form::textarea('body') !!}
      &lt;/p&gt;
  
      &lt;p&gt;
          {!! Form::label('published_at', 'Date:') !!}
          {!! Form::input('date', 'published_at', date('Y-m-d'), ['class' =&gt; 'form-control']) !!}
      &lt;/p&gt;
  
      &lt;p&gt;
          {!! Form::submit('Submit Article', ['id' =&gt; 'submit']) !!}
      &lt;/p&gt;
  {!! Form::close() !!}
  
  &lt;/body&gt;
  &lt;/html&gt;   
  </code></pre>
  
  <p><strong>route.php</strong></p>
  
  <pre><code>Route::resource('articles', 'ArticlesController');
  </code></pre>
  
  <p><strong>Article controller</strong></p>
  
  <pre><code>public function store()
      {
          print_r(Request::all());
  
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/3zI62.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3zI62.png" alt="enter image description here"></a></p>
  
  <p><strong>Update 2</strong></p>
  
  <pre><code>[2015-08-28 06:23:03] 
  
  local.ERROR: exception 'Illuminate\Session\TokenMismatchException' in D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php:53
  Stack trace:
  #0 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #1 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
  #2 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(54): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #3 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #4 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
  #5 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(62): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #6 [internal function]: Illuminate\Session\Middleware\StartSession-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #7 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
  #8 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #9 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #10 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
  #11 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(59): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #12 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #13 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
  #14 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(42): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #15 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
  #16 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array)
  #17 [internal function]: Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  #18 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
  #19 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(122): Illuminate\Pipeline\Pipeline-&gt;then(Object(Closure))
  #20 D:\xampp\htdocs\demo\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(87): Illuminate\Foundation\Http\Kernel-&gt;sendRequestThroughRouter(Object(Illuminate\Http\Request))
  #21 D:\xampp\htdocs\demo\public\index.php(54): Illuminate\Foundation\Http\Kernel-&gt;handle(Object(Illuminate\Http\Request))
  #22 {main}  
  </code></pre>