Может быть, это будет дубликат, но я не могу найти правильного решения проблемы .. Фактическая проблема заключается в том, что вызов ajax работает хорошо и возвращает данные ответа для таблицы, но таблица всегда показывает только загрузку. здесь
UserController.php
if ($request->ajax())
{
$users = User::select('id','name','email','phone','created_at','updated_at')->where('id','!=',Auth::user()->id)->get();
return DataTables::of($users)
->editColumn('action', function ($user) {
return ' <a class = "icon-color" href = "'.route('users.edit',$user->id).'"><i class = "fa fa-edi" aria-hidden = "true"></i></a>
<a class = "icon-color" href = "'.route('users.show',$user->id).'"><i class = "fa fa-eye" aria-hidden = "true"></i></a>
<a class = "icon-color" href = "'.route('users.destroy',$user->id).'"><i class = "fa fa-trash" aria-hidden = "true"></i></a>';
})
->rawColumns(['action'])
->make(true);
}
return view('manager.users.index');
index.blade.php
<table id = "users-table" class = "table table-striped table-no-bordered table-hover" >
<thead style = "font-size: 12px;" class = "text-primary">
<tr>
<th style = "text-align: center" width = "5%">#</th>
<th style = "text-align: center" width = "20%">Name</th>
<th style = "text-align: center;" width = "25%">Email</th>
<th style = "text-align: center;" width = "10%" >Phone</th>
<th style = "text-align: center;" width = "15%" >Created Date</th>
<th style = "text-align: center;" width = "15%" >Updated Date</th>
<th style = "text-align: center;" width = "10%">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
script
$('#users-table').DataTable({
"lengthMenu": [
[10, 25, 50, -1],
[10, 25, 50, "All"]
],
processing: true,
serverSide: true,
responsive: true,
ajax:{
url:"{{route('users.index')}}",
type:'get',
success:function(xhr){
toastr.success('Completed!')
}
},
columns: [
{data:'id',name:'id'},
{data: 'name', name: 'name'},
{data: 'email', email: 'email'},
{data: 'phone', name: 'phone'},
{data: 'created_at', name: 'created_at'},
{data: 'updated_at', name: 'updated_at'},
{data: 'action', searchable:false},
],
"order":[[0,'desc']]
});
и здесь я делаю снимок экрана без ответа на запрос

любой, кто сможет найти решение ... любое исцеление было бы очень признательно. Благодарность..
я пробовал это, но не работает ..






измените вызов ajax, а также удалите свойство тип и успех из ajax.
ajax:{
url:"{{route('users.index')}}",
type:'get',
success:function(xhr){
toastr.success('Completed!')
}
},
в
ajax: '{{ route('users.index') }}',
Надеюсь, это будет полезно. Остальная часть кода верна.
Я могу получить ответ на звонок, но данные не загружаются в таблицу .. вы можете видеть это на изображении ..
Вы можете изменить свой вызов ajax и проверить, загружаются ли данные в таблицу или нет
$('#users-table').DataTable({
"lengthMenu": [
[10, 25, 50, -1],
[10, 25, 50, "All"]
],
processing: true,
serverSide: true,
ajax:{
url:"{{route('users.index')}}",
},
columns: [
{data: 'id', name:'id'},
{data: 'name', name: 'name'},
{data: 'email', name: 'email'},
{data: 'created_at', name: 'created_at'},
{data: 'updated_at', name: 'updated_at'},
{data: 'action'},
],
"order":[[0,'desc']]
});
Just issue with ajax call
это не проблема, вы можете указать тип вызова, получить или не опубликовать проблему с этим
удалите тег tbody из своей таблицы.