提问人:Angel 提问时间:6/15/2022 更新时间:6/15/2022 访问量:154
Laravel:datatable 服务器端支持的方法
Laravel: datatable Server side Supported method
问:
我正在尝试将数据表用作服务器端,但遇到错误“此路由不支持 GET 方法。支持的方法:POST。我已经尝试了我找到的所有解决方案,但不幸的是它没有奏效。
视图
<table id="loan-details-table" class="table table-striped table-bordered table-sm">
<thead class="thead-global">
</thead>
<tbody></tbody>
</table>
<script type="text/javascript">
//function in calling datatable ajax
function getGeneratedLoanDetails(){
var table = $('#loan-details-table').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '/configurations/penalties/getGeneratedLoanDetails/',
dataType: "json",
type: "POST",
data:{ _token: "{{csrf_token()}}"}
},
columns: [
{ data: '#' },
{ data: 'number' },
{ data: 'name' },
{ data: 'date_granted' },
{ data: 'current_date' },
{ data: 'no_of_days' },
{ data: 'daily_amortization_amount' },
{ data: 'total_amortization_amount' },
{ data: 'total_amount_paid' },
{ data: 'difference' },
{ data: 'days_delay' },
{ data: 'interest_rate'},
{ data: 'penalty_amount'},
{ data: 'action' }
]
});
}
$(document).ready(function(){
//datatable ajax
setTimeout(
function()
{
getGeneratedLoanDetails();
}, 500);
})
</script>
蹼
Route::post('/configurations/penalties/getGeneratedLoanDetails/', 'Penalty\PenaltyController@getGeneratedLoanDetails');
问题:为什么我遇到这个错误,即使我已经在我的视图和路由中将其声明为POST?
答:
0赞
Nguyen Anh Thai
6/15/2022
#1
您可以尝试在参数的末尾删除吗?此外,您也可以在 Laravel 代码中在路线的末尾删除。/
url
ajax
/
更改为/configurations/penalties/getGeneratedLoanDetails/
/configurations/penalties/getGeneratedLoanDetails
评论
Route::post('/configurations/penalties/getGeneratedLoanDetails/', function(){ return '{"data":[]}'; });
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.12.1/datatables.min.css"/> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.12.1/datatables.min.js"></script>