am having trouble with the live search function. it not doing anything and i cant figure out where the problem is. here is my contoller
public function liveSearch(Request $request)
{
if ($request->ajax()) {
$output = '';
$none = 'none';
$particulars = DB::table('particulars')
->orderBy('particular_id')
->where('item_name', 'LIKE', '%'.$request->search.'%')
->orWhere('category', 'LIKE', '%'.$request->search.'%')
->limit(5)->get();
if ($particulars) {
foreach ($particulars as $particular) {
$output .= '<tr>'.
'<td class="text-center">'.$particular- >item_name.'</td>'.
'<td class="text-center">'.$particular->unit.'</td>'.
'<td class="text-center">'.$particular->quantity.'</td>'.
'<td class="text-center">'.$particular->category.'</td>'.
'<td class="text-center">'.$particular->price.'</td>'
.'</tr>';
}
return Response($output);
}else{
return Response()->json(['no'=>'not found']);
}
}
}
here is the javascript code
$('#search').on('keyup', function(){
$value = $(this).val();
$none = '<p id="noResults" class="alert alert-danger">No results</p>'
$.ajax({
type: 'GET',
url: './searchit',
data: {'search':$value},
success: function(data){
if (data == '') {
$('#noResults').replaceWith($none);
$('#table').hide();
}
else{
$('#table').show();
$('#pagination').hide();
$('tbody').html(data);
$('#noResults').hide();
}
}
});
});
here is the root
Route::get('searchit','ApproverController@AutoSearch');
here is the view
<div class="row">
<div class="col-lg-12" style="margin: 10px 1px;">
<div class="input-group">
<div class="input-group-addon">
<span class="fa fa-search"></span>
</div>
<input type="text" class="form-control" id="search" placeholder="Search here...">
</div>
</div>
</div>
And i have included the source in the layout as this
<script src=""></script>
@yield('script')
please anyone who can sport the problem, help, thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire