title: Retrieve records into table using Ajax in Laravel
body: <p>Please, i need assistance to this code. I have a dropdown list,showing different type of accounts. I want to be able to display transactions belonging to those accounts on change events from the dropdown. I am able to do this, using the traditional php and ajax. But i am just learning the laravel frameworks and i am stuck.Please help me look and see where i am missing it or a better way of achieving this feat.</p>
  
  <p>See View:</p>
  
  <pre><code>&lt;form role="form"&gt;
   &lt;div class="col-md-8"&gt;
   &lt;select name="grpid" class="form-control" id="grpid"&gt;
      @foreach($account as $account)
      &lt;option value="{{$account-&gt;code}}"&gt;{{$account-&gt;accountName}}&lt;/option&gt;
      @endforeach
   &lt;/select&gt;&lt;/div&gt;&lt;div class="col-md-4"&gt;
  &lt;button type="button" name="sbt" class="sbt btn btn-block btn-success"   id="sbt"&gt;Retrieve&lt;/button&gt;&lt;/div&gt;
  &lt;/form&gt;
       &lt;/div&gt;
      &lt;br/&gt;
       &lt;br/&gt;
     &lt;/h2&gt;
     &lt;div id="tableview"&gt;&lt;/div&gt; 
    &lt;/div&gt;
   &lt;/div&gt;&lt;/div&gt;
  @endsection
  &lt;script src="/mat/js/newJquery.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
   $('#grpid').on("change",function(){
    var sid = $(this).val();
    var div = $(this).parent();
    var op =" ";
  
    $.ajax({
      type:'post',
      url: '/postForm',
      data:{
         '_token':$('input[name=_token]').val(),
         'selectedid': sid;
          },
          success: function(data){
          op+='&lt;table&gt;';
          op+='&lt;tr&gt;&lt;th&gt;SN&lt;/th&gt;&lt;th&gt;Date&lt;/th&gt;&lt;th&gt;Account Type&lt;/th&gt;&lt;th&gt;Narration&lt;/th&gt;&lt;th&gt;Amount&lt;/th&gt;&lt;/tr&gt;';
          for(var i=0;i&lt;data.length;i++){
            op+='&lt;tr&gt;';
            op+='&lt;td&gt;'+i+'&lt;td&gt;&lt;tr&gt;';
            op+='&lt;tr&gt;&lt;td&gt;'+data[i].transdate+'&lt;/td&gt;&lt;/tr&gt;';
            op+='&lt;tr&gt;&lt;td&gt;'+data[i].acctype+'&lt;/td&gt;&lt;/tr&gt;';
            op+='&lt;tr&gt;&lt;td&gt;'+data[i].accounts_code+'&lt;/td&gt;&lt;/tr&gt;';
            op+='&lt;tr&gt;&lt;td&gt;'+data[i].narration+'&lt;/td&gt;&lt;/tr&gt;';
            op+='&lt;tr&gt;&lt;td&gt;'+data[i].amount+'&lt;/td&gt;&lt;/tr&gt;';
            op+='&lt;/tr&gt;';
          }
           op+='&lt;/table&gt;';
           div.find('#tableview').append(op);
         },
          error: function(){
            console.log("Error Occurred");
          }
      });
  
   });
  
   });
  </code></pre>
  
  <p></p>
  
  <p>See postForm method of the Controller</p>
  
  <pre><code> public function postForm(Request $request)
      {
         $data = Accounttrans::where('accounts_code',$request-&gt;selectedid)-&gt;get();
          return response()-&gt;json($data);
      }
  </code></pre>
  
  <p>Route for the form:</p>
  
  <pre><code>Route::get('/openform','AccounttransController@openform');
  Route::post('/postForm','AccounttransController@postForm');
  </code></pre>
  
  <p>Kindly help. I want to display the result in a table format.</p>