This is my ajax code. I want to type something in a textbox, and the result from database should 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 changing 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 that will show at the table:
public function dataAjaxCountry()
{
echo "<tr><td>asdsad</td></tr>";
}