Я работаю с живым поиском в laravel и использую Ajax и jQuery, но мой код не работает, показывая эту ошибку
ET http://127.0.0.1:800/data_list?%20data=hj 500 (Внутренняя ошибка сервера)
Это загрузчик моего кода
<div class="card col-lg-9">
<div class="card-title mt-3">
<div class="align-lift"><h4>Solar & Power Energy <span class="pull-
right">Total Row:</span><span
id="tootal_record"></span></h4></div>
<div align="right">
<input class="form-control col-lg-4 pull-right" id="search"
name="search" placeholder="search"
type="text">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
</div>
</div>
<div class="card-body">
<div class="table table-responsive">
<table class="table table-striped table-bordered table-active">
<thead class="shadow bg-yellow text-white ">
<th>Id</th>
<th>Title</th>
<th>Text</th>
<th>Date</th>
<th>Video</th>
<th>Photo</th>
<th>Action</th>
</thead>
<tbody class="bg-white">
</tbody>
</table>
</div>
</div>
</div>
Это код javaScript
<script>
$(document).ready(function () {
fetch_customer_data();
function fetch_customer_data(query) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: "{{ route('spes_data_list') }}",
method: 'GET',
data: {
' data': query
},
dataType: 'json',
success: function (data) {
$('tbody').html(data.table_data);
$('#tootal_record').text(data.total_data);
}
})
}
$('#search').on( 'keyup',function () {
var query = $(this).val();
fetch_customer_data(query);
console.log(query);
});
});
</script>
Это код laravel
class ServicesController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function data_spes_list_from_database(Request $request)
{
if ($request->ajax()) {
$query = $request->get('data');
if (!empty($query )) {
$data = DB::table('services')->where('title', 'like', '%' . $query . '%')
->orWhere('photo', 'like', '%' . $query . '%')
->orWhere('vide', 'like', '%' . $query . '%')
->orWhere('id', 'like', '%' . $query . '%')
->get();
} else {
$data = DB::table('services')->orderBy('id', 'desc')->get();
}
$total_row = $data->count();
if ($total_row > 0) {
foreach ($data as $row) {
$output = '
<tr>
<td>' . $row->id . '</td>
<td>' . $row->title . '</td>
<td>' . $row->text . '</td>
<td>' . $row->created_at . '</td>
<td>' . $row->video . '</td>
<td><img style="width:100px;height:100px;" class="" src="' .
url ('img / user_img /'. $ Row-> photo). '">
</tr>
';
}
} else {
$output = '
<tr>
<td align="center" colspan="5" >No Data Found </td>
';
}
$data = array(
'table_data' => $output,
'total_data' => $total_row
);
echo json_encode($data);
}
}
Это маршрут web.php
Route::get('/data_list',
'admin\ServicesController@data_spes_list_from_database')
->name('spes_data_list');
Route::post('/edit_list','admin\ServicesController@editSpesList')-
>name('spes_edit_list');