2 回答

TA貢獻1995條經驗 獲得超2個贊
像這樣進行更改:
希望它會幫助你
路線文件:
Route::get('/appointments','NavigationController@Appointments')->name('appointments');
Html 代碼:
把它放在你的 head 部分
<meta name="csrf-token" content="{{ csrf_token() }}">
這是你的桌子:
<table class="table" id="appointment-datatable">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">date</th>
<th scope="col">time</th>
<th scope="col">payment_status</th>
<th scope="col">amount</th>
</tr>
</thead>
</table>
控制器代碼:
public function Appointments(Request $request)
{
if ($request->ajax()) {
$data = DB::table('jobs')->select('id', 'date', 'time', 'payment_status', 'amount')->get();
return Datatables::of($data)
->addIndexColumn()
->make(true);
}
return view('admin.show_appointments');
}
阿賈克斯代碼:
$(function () {
$('#appointment-datatable').DataTable({
processing: true,
serverSide: true,
ajax: "{{ route('appointments') }}",
columns: [
{data: 'id', name: 'id'},
{data: 'date', name: 'date'},
{data: 'time', name: 'time'},
{data: 'payment_status', name: 'payment_status'},
]
});
});
我希望它會幫助你

TA貢獻1850條經驗 獲得超11個贊
嘗試在標題中添加令牌
<meta name="csrf-token" content="{{ csrf_token() }}" />
并在您的 ajaxSetup 或數據中添加令牌
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
還要更改 getAppointmentData 函數。
public function getAppointmentData(Request $request)
{
if ($request->ajax())
{
$getData = DB::table('jobs')->select('id', 'date', 'time',
'payment_status', 'amount');
return DataTables::of($getData)->make(true);
}
}
- 2 回答
- 0 關注
- 161 瀏覽
添加回答
舉報