title: Laravel 5.3 Ajax - Retrieve data sent in the ajax request from the controller
body: <h3>index.html</h3>
  
  <pre><code>&lt;form id="my-form"&gt;
   &lt;select id="my-select"&gt;
    &lt;option value="1"&gt;Tom&lt;/option&gt;
    &lt;option value="2"&gt;Jerry&lt;/option&gt;
   &lt;/select&gt;
   &lt;input type="submit" value="send data!"&gt;
  &lt;/form&gt;
  </code></pre>
  
  
  
  <h3>Controller.php</h3>
  
  <pre><code>public function getValue(Request $request)
  {
   return User::find($request-&gt;input('select_id'));
  }
  </code></pre>
  
  <h3>ajax.js</h3>
  
  <pre><code>$(function () {
  
  $.ajaxSetup({
      headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      }
  });
  
  var showUser = $('#show-user');
  
  $('#my-form').on('submit', function () {
  
      var select_id = $('#my-select').val();
  
      $.ajax({
          method: "POST",
          url: "ajax",
          headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          },
          data: {
              "select_id": select_id
          },
          error: function (data) {
              //something went wrong with the request
              alert("Error");
          },
          success: function (data) {
              inner = "";
              data.forEach(function (el, i, array) {
                  inner += "&lt;div&gt;" + el.name + "&lt;/div&gt;";
              });
              showUser.html(inner);
          }
      });
      event.preventDefault();
  });
  </code></pre>
  
  <p>});</p>
  
  <h3>web.php</h3>
  
  <pre><code>Route::post('ajax','Controller@getValue');
  </code></pre>
  
  <h3>Update:</h3>
  
  <p>@Mahdi Youseftabar -> Thanks for it, according to the documentation I should use input() to get the request!</p>
  
  <p><strong>Problem 1: Error: 500 (TokenMismatchException);</strong></p>
  
  <p><strong>What I did?</strong></p>
  
  <p>Add meta to :</p>
  
  <pre><code>&lt;meta name="csrf-token" content="{{ csrf_token() }}"&gt;
  </code></pre>
  
  <p>I set the headers:</p>
  
  <pre><code>$.ajaxSetup({
      headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      }
  });
  
      $.ajax({
      ...
          headers: {
              'X-Auth-Token' : token
          },
      ...
      });
  </code></pre>
  
  <h2>What I need to do?</h2>
  
  <ul>
  <li><em>Retrieve the id sent in the ajax request from the controller</em> [SOLVED]</li>
  <li><em>Validate the token by the ajax request** Error 505 (Problem 1)</em> [SOLVED]</li>
  <li><em>Return from the controller is Empty</em> [SOLVED]</li>
  <li><em>Output the Users into the <code>&lt;div class="showUser"&gt;&lt;/div&gt;</code></em> [SOLVED]</li>
  </ul>
  
  <p><strong>Github Documentation of my project:</strong> 
  (Many to many relationships - Laravel 5.3, Ajax)
  <a href="https://github.com/39ro/StudentSchoolProject" rel="nofollow noreferrer">https://github.com/39ro/StudentSchoolProject</a></p>