使用ajax请求在laravel 5.4中删除记录时发出问题?

时间:2017-06-28 11:39:22

标签: php mysql routes laravel-5.4

我想使用laravel 5.4使用ajax调用删除记录。我尝试了很多,但删除是不工作意味着无法从数据库中删除记录。 这是我的观点:

 <div class="btn-sm btn-danger pull-right delete" data-token="{{ csrf_token() }}" s data-id="{{$menus->id}}">
                                            <i class="voyager-trash"></i> Delete
                                        </div>

脚本:

<script>
        $(document).ready(function () {

$('.delete').click(function(){
 var id=$(this).data("id");
 var token=$(this).data("token");

$.ajax(
        {
            url: "skillset/delete/"+id,
            type: 'DELETE',
            dataType: "JSON",
            data: {
                "id": id,
                "_method": 'DELETE',
                "_token": token,
            },
            success: function ()
            {
                console.log("okie");
            }
        });

        console.log("not okie");


})

        });
    </script>

控制器:

public function delete($id)
    {
echo'hii';

     return $result= Skillset::destroy($id);
    }

路线:

// Route skill set
           Route::group([
            'as' => 'skillset.',
            'prefix' => 'skillset',
                ], function () use ($namespacePrefix) {
            Route::get('/', ['uses' => $namespacePrefix . 'Skillsetcontroller@index', 'as' => 'index']);
            Route::post('/', ['uses' => $namespacePrefix . 'Skillsetcontroller@store', 'as' => 'store']);
            Route::delete('/skillset/delete/{id}', ['uses' => $namespacePrefix . 'Skillsetcontroller@delete', 'as' => 'destroy']);

        });

当我点击删除按钮时,我的控制台会给我路径

DELETE 
XHR 
http://127.0.0.1:8000/admin/skillset/delete/1

任何人都可以告诉我解决方案。任何帮助都将不胜感激。

0 个答案:

没有答案