小编PoT*_*Tii的帖子

Laravel 5.4 + Ajax等于401 Unauthenticated

每当我尝试从我的api.php文件中分配路由时,我得到一个401: Unauthenticated-Error.

这是路线:

Route::group(['prefix' => 'v1', 'middleware' => 'auth:api'], function () {
    Route::post('admin/product-image-sort', 'ApiController@SaveProductImageSort')->name('api.save-product-image-sort');
});
Run Code Online (Sandbox Code Playgroud)

我使用Jquery Ajax调用它:

<script>

        $('#sortable-image-container').sortable({
            items: '> .row > *',
            update: function (event, ui) {
                var data = $(this).sortable('serialize');
                console.log(data);
                $.ajax({
                    data: data,
                    type: 'POST',
                    url: "{{ route('api.save-product-image-sort') }}",
                    success: function (data) {
                        if(data == "success"){
                            $.notify({
                                icon: 'pe-7s-close-circle',
                                message: "Sucessfully saved the Image Sorting"
                            },{
                                type: 'success',
                                timer: 500
                            });
                        }
                    }
                });
            }
        });
    </script>
Run Code Online (Sandbox Code Playgroud)

因此,在排除'middleware' => 'auth:api'部件时这可以完美无缺,但我不想仅仅允许在没有任何形式的身份验证的情况下访问我的内部api. …

ajax jquery csrf http-status-code-401 laravel-5

7
推荐指数
1
解决办法
8749
查看次数

标签 统计

ajax ×1

csrf ×1

http-status-code-401 ×1

jquery ×1

laravel-5 ×1