提问者:小点点

Laravel 5.5方法不允许HttpException ajax


我试图通过ajax请求发布一些数据。

这是我视图中的javascript代码。刀身php,它指的是http://mysite/element/edit/{id}

<script>
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $(function() {
        $( "#append-content" ).sortable({ handle: '.composer-row-header-handle' }).bind('sortupdate', function(e, ui) {

            var rowID = $('.composer-row').map(function(){
                return $(this).attr("id");
            }).get();

            $.ajax({
                type: "POST",
                url: "sort/store",
                dataType: "json",
                data: {
                    rowID: rowID
                },
                success: function(order){
                    console.log(rowID)
                },
                error: function(){
                    console.log(rowID)
                }
            });
        });

    });
</script>

在同一个文件中,我插入了相对的_标记元

<meta name="csrf-token" content="{{ csrf_token() }}">

然后,我在路由文件中设置了一个POST路由

Route::post('element/edit/sort/store', 'ElementsController@sort');

我的ElementsController排序函数是

public function sort(Request $request)
{
    $rowID = $request->input('rowID');
    $i = 1;

    foreach($rowID as $val) {
        $val = str_replace("row-", "", $val);
        DB::table('element')
            ->where('refID', 1)
            ->where('rowID', $val)
            ->update(
                [
                    'rowORDER' => $i,
                ]
            );
        $i++;
    }
}

但是当我尝试重新排序日志时,响应是

jquery-1.12.0.min.js:4 POST http://mysite/element/edit/sort/store 500 (Internal Server Error)

如果我尝试打开链接在一个新的网页这是结果

错误页面

提前感谢您的回答


共2个答案

匿名用户

解决了的,

可能工作时间太长了。我在错误的控制器文件上编辑排序函数。

匿名用户

将{URL::更改为('element/edit/sort/store')}并重试