Laravel:DataTable服务器端支持的方法

发布于 2025-02-07 10:17:40 字数 1868 浏览 1 评论 0原文

我试图将DataTable用作服务器端,但遇到错误“ 对于此路线不支持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>

web

Route::post('/configurations/penalties/getGeneratedLoanDetails/', 'Penalty\PenaltyController@getGeneratedLoanDetails');

问题:为什么我在我的视图中已经声明了这个错误,&amp;路线作为帖子?

I am trying to use the datatable as a server side but encountered error "The GET method is not supported for this route. Supported methods: POST.". I already tried all the solutions I've found but unfortunately it didn't work.

View

<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>

Web

Route::post('/configurations/penalties/getGeneratedLoanDetails/', 'Penalty\PenaltyController@getGeneratedLoanDetails');

Question: Why Im encountering this error even tho I already declared it in my view & route as POST?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等风来 2025-02-14 10:17:40

您可以尝试在url的末尾删除/ ajax param中的吗?此外,您也可以在路线末端以Laravel代码删除/

更改/configurations/fine/getGeneratedLoandetails/ /configurations/fine/getGenerateDloandetails

Can you try removing / at the end of url in ajax param? Moreover, you could remove / at the end of your route in Laravel code too.

Change /configurations/penalties/getGeneratedLoanDetails/ to /configurations/penalties/getGeneratedLoanDetails

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文