title: Receive data from an $.ajax call with laravel controller
body: <p>I am trying to take selected option from <code>&lt;select&gt;</code>, pass it through to method <code>show()</code> in controller, use it to retrieve data from database, and then return it as json to the success method in <code>$.ajax</code>. All this is happening through <code>jquery.ajax</code>.</p>
  
  <h1>My Problem</h1>
  
  <p>How can i get/receive data i pass from <code>$.ajax</code> request to manipulate the database?</p>
  
  <p>Here is the code I am using:</p>
  
  <h3>routes.php</h3>
  
  <pre><code>Route::post('rate/units',array('as'=&gt;'unitRoute','uses'=&gt;'RateController@show'));
  </code></pre>
  
  <h3>RateController.php</h3>
  
  <pre><code>public function show()
  {
      $row[] = $_POST['deg'];
  
      return json_encode($row);
  }
  </code></pre>
  
  <h3>Views</h3>
  
  <pre><code>&lt;select class="form-control choosedegree" name="sem" id="semester"&gt;
      &lt;option value="" selected="selected" disabled&gt;Select Semester&lt;/option&gt;
      &lt;option value="1"&gt;Year 1, Semester 1&lt;/option&gt;
      &lt;option value="2"&gt;Year 1, Semester 2&lt;/option&gt;
      &lt;option value="3"&gt;Year 2, Semester 1&lt;/option&gt;
      &lt;option value="4"&gt;Year 2, Semester 2&lt;/option&gt;
      &lt;option value="5"&gt;Year 3, Semester 1&lt;/option&gt;
      &lt;option value="6"&gt;Year 3, Semester 2&lt;/option&gt;
      &lt;option value="7"&gt;Year 4, Semester 1&lt;/option&gt;
      &lt;option value="8"&gt;Year 4, Semester 2&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;script&gt;
  $(document).ready(function() {
      $('select#semester').on('change', function() {
          var optionSelected = $(this).find("option:selected");
          semesterSelected  = optionSelected.val();
          console.log(semesterSelected);
  
          $.ajax({
              type: "POST",
              cache: false,
              url : "rate/units",
              data: { sem : semesterSelected },
              success: function(data) {
                  var obj = $.parseJSON(data);
                  var i = 0;
                  console.log(data.iyo);
  
                  $.each(obj, function() {
                      console.log(this[0]);
                      console.log(this[1]);
                      console.log(this[2]);
                      console.log(this[3]);
                      console.log(this[4]);
  
                      i++;
                  });
              }
          })
          .done(function(data) {
              alert('done');
          })
          .fail(function(jqXHR, ajaxOptions, thrownError) {
              alert('No response from server');
          });
      });
  });
  &lt;/script&gt;
  </code></pre>