Laravel search data with AKAX

this is my ajax code, i want to type something in textbox, and the result from database will show at the table..

<script type="text/javascript">
  function retrieve(){
    var country = $('#country_name').val();
    $.ajax({
      type: "POST",
      url: '{{route('dataAjax-country')}}',
      data: {country:country},
      success: function(result){
        $('#ajaxtable').html(result);
      }
    });
  }
</script>

but the data is not change when i type on my textbox, i have a textbox and a table like this..

{!! Form::text('country_name', '', array('id'=>'country_name', 'onkeyup'=>'retrieve()')) !!}

<tbody id="ajaxtable">
  @foreach($results as $result)
    <tr>
      <td>{{$result->id}}</td>
      <td>{{$result->country_name}}</td>
    </tr>
  @endforeach
</tbody>

and this is my route code, maybe i lack at my route(?):

Route::get('asd', array(
        'as' => 'dataAjax-country', 'uses' => 'CompaniesController@dataAjaxCountry'));

and my controller that contain AJAX script tah will show at the table:

public function dataAjaxCountry()
{
    echo "<tr><td>asdsad</td></tr>";
}


Source: laravel

Leave a Reply