title: Laravel 5.2: how to pass data to controller using ajax
body: <p>Hi I am new to Laravel and I am trying to pass some data to controller using an ajax call.</p>
  
  <p><strong>Route</strong></p>
  
  <pre><code>Route::post('/category', 'FrontendController@category');
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code> public function category(Request $request){
  
       $data = $request-&gt;all();
   }
  </code></pre>
  
  <p><strong>Ajax call</strong></p>
  
  <pre><code> var name= 'John';
  
          $.ajax({
              method: 'post',
              url: '{{url("/category")}}', 
              data: {'name' : name}, 
              success: function(response){ 
                  console.log(response);
  
              },
              error: function(jqXHR, textStatus, errorThrown) {
                  console.log(JSON.stringify(jqXHR));
                  console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
              }
          });
  </code></pre>
  
  <p>Using the code above I gef following error: <br />
  <strong>MethodNotAllowedHttpException in RouteCollection.php line 218</strong></p>