I'km trying the autocomplete by selecting data from DB and getting back the response as json but all I got is internal server error, could it be a problem of csrf token?
this is the script
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js" ></script>
<script type="text/javascript">
$(document).ready(function () {
$('input:text').bind({
});
$("#auto").autocomplete({
minLength:2,
source: '{{ URL('getdata') }}'
});
});
</script>
and this in the controller:
public function getData(){
$term = Input::get('term');
$data = DB::table('items')->distinct()->select('item_name')->where('word', 'LIKE', $term.'%')->groupBy('word')->take(10)->get();
foreach ($data as $v) {
$return_array[] = array('value' => $v->word);
}
return Response::json($return_array);
}
Problem was in getData function, this one works.
public function getData(){
$term = Input::get('term');
$data = DB::table('items')->distinct()->select('item_name')->where('item_name', 'LIKE', $term.'%')->groupBy('item_name')->take(10)->get();
foreach ($data as $v) {
$return_array[] = array('value' => $v->item_name);
}
return Response::json($return_array);
}