Returning data from AJAX in Laravel
<p>My lecturer gave me a project for me and my friend, creating an app using newest Laravel framework. I'm not to familiar with this framework. I'm trying to load a data to my view using AJAX. </p>

<p><a href="http://i.stack.imgur.com/G6ZGP.png" rel="nofollow">User Navigation for searching customer</a></p>

<p>This is the code for displaying the table</p>

<pre><code>@foreach($mpelanggan as $mpelanggan)
    {{ Form::open() }}
    {{ Form:: hidden('_method' ,'DELETE')}}
         &lt;tr&gt;
            &lt;p hidden id="kd" value="{{$mpelanggan-&gt;Kd_Pelanggan}}"/&gt;
            &lt;td&gt;{{$mpelanggan-&gt;Perusahaan}}&lt;/td&gt;
            &lt;td align="center"&gt;
                &lt;button type="button" class="btntransparant" value="{{$mpelanggan-&gt;Perusahaan}}" id="ch"&gt;
                    &lt;span class="glyphicon glyphicon-plus" aria-hidden="true"&gt;&lt;/span&gt;
                &lt;/button&gt;
            &lt;a class="fontblack" &gt;
                &lt;span class="glyphicon glyphicon-pencil" aria-hidden="true"&gt;&lt;/span&gt;
            &lt;/a&gt; &amp;nbsp
            &lt;button type="submit" class="btntransparant" onclick="return confirm('Are you sure you want to delete this data?');"&gt;
                &lt;span class="glyphicon glyphicon-trash" aria-hidden="true"&gt;&lt;/span&gt;
            &lt;/button&gt;
        &lt;/a&gt;
    &lt;/td&gt;
&lt;/tr&gt;
{!!Form::close()!!}
@endforeach
</code></pre>

<p>When user click the + button it will load the list of his transaction in this table:
<br/></p>

<p><a href="http://i.stack.imgur.com/j0Tdj.png" rel="nofollow">Customer Transaction</a></p>

<p><b>My Routes:</b></p>

<pre><code>Route::get('trans','TransController@index');
Route::get('getBTB',array('as'=&gt;'getBTB','uses'=&gt;'TransController@getBTB'));
</code></pre>

<p><b>My Controller TransController:</b></p>

<pre><code>public function index(){
 $Mpelanggan = Mpelanggan::all();
 return view('tr.nav')-&gt;with('mpelanggan' , $Mpelanggan);
}


public function getBTB(Request $request){
  $term = $request-&gt;term;
  $data = Trbtb_h::where('Kd_Pelanggan',$term)-&gt;get();
  $result=array();
  foreach ($data as $key =&gt; $value) {
    $result[]=['No_BTB'=&gt;$value-&gt;No_BTB,'Tgl_BTB'=&gt;$value-&gt;Tgl_BTB];
  }
 return Response::json(array('success'=&gt;true,'result'=&gt;$result));
}
</code></pre>

<p><b>The AJAX</b></p>

<pre><code>        $('#ch').click(function(){
         var np=$(this).attr('value');
         var get=$('#table1 &gt; tbody');
         $('#btb-title').text(np);
         $("#pnl-btb").show();
         $("#pnl-faktur").show();
         $("#pnl-bayar").show();
         $("#pnl-btb-list").show();
         $.ajax({
            url         :'getBTB',
             type       :'GET',
             dataType   :'JSON',
             success    :'success',
             data       :{'term':kd},
             success    :function(result){
                 var data = JSON.parse(result);
                 var x;
                 for(x=0;x&lt;data.length;x+=1){
                     var dat = data[i];
                     get.append('&lt;tr&gt;&lt;td&gt;'+dat.No_BTB+'&lt;/td&gt;&lt;td&gt;'+dat.Tgl_BTB+'&lt;/td&gt;&lt;td align="center"&gt;&lt;button type="button" class="btntransparant" value="" id="ch"&gt;&lt;span class="glyphicon glyphicon-plus" aria-hidden="true"&gt;&lt;/span&gt; &lt;/button&gt; &lt;a class="fontblack" &gt; &lt;span class="glyphicon glyphicon-pencil" aria-hidden="true"&gt;&lt;/span&gt; &lt;/a&gt; &amp;nbsp&lt;button type="submit" class="btntransparant&gt;&lt;span class="glyphicon glyphicon-trash" aria-hidden="true"&gt;&lt;/span&gt;&lt;/button&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;');
                 }
             }
         })
        });
</code></pre>

<p>I want to put the data from $result in the btody tag, just like the customer list table.</p>

<pre><code>    &lt;div class="row" id="pnl-faktur"&gt;
        &lt;table class="table table-striped table-bordered" id="table2"&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                    &lt;th&gt;Plh&lt;/th&gt;
                    &lt;th&gt;No. Faktur&lt;/th&gt;
                    &lt;th&gt;Tanggal&lt;/th&gt;
                    &lt;th&gt;Jatuh Tempo&lt;/th&gt;
                    &lt;th&gt;Piutang&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;

            &lt;/tbody&gt;
            &lt;tfoot&gt;
                &lt;td colspan="4" align="right"&gt;Total&lt;/td&gt;
                &lt;td&gt;&lt;input type=text/&gt;&lt;/t&gt;
            &lt;/tfoot&gt;
    &lt;/div&gt;
</code></pre>

<p>I watched some tutorial about AJAX and Laravel but none that I understand, I dont know what to do to load the $result to my view in the AJAX script.
This is my first question in stackoverflow, if i made any mistake im sorry</p>