Having problems to pass searched data from controller blade file using ajax in laravel

This is my controller method in Admin Controller , this method receive the search input but i am facing problems to pass output data to the view file

public function action(Request $request)
{
if($request->ajax())
{

$students=Student::where('name','LIKE','%'.$request->search."%")->paginate(5);

$data = $students->count();
if($data > 0)
{
$output=$students;

}
else{
$output=$students;
}
return view('search' compact('output'));

}

}

Here is the ajax in view file (search.blade.php)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript">

// $(document).on('keyup', '#search', function(){
$('#search').on('keyup',function(){
$value=$(this).val();
$.ajax({
type : 'get',
url : '',
data:{'search':$value},
success:function(data){
$('tbody').html(data);
}
});

})

</script>

<script type="text/javascript">
$.ajaxSetup({ headers: { 'csrftoken' : '' } });
</script>

Here is the ajax route

Route::get('/search/action', 'AdminController@action')->name('search.action');


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/396qnfs
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time