dongmaopiao0901 2016-10-11 11:17
浏览 83
已采纳

使用AJAX删除Laravel 5.3中的记录

I'm getting the next error:

jquery-2.2.4.min.js:4 DELETE http://company.dev/admin/portfolio/settings/category/delete/7 500 (Internal Server Error)

I'm not sure what it is because I think I have the right route and also giving the csrf token (still fairly new to laravel)

Route:

   Route::delete('/admin/portfolio/settings/category/delete/{id}', [
      'as' => 'categoryDelete',
      'uses' => 'PortfolioController@destroy'
   ]);`enter code here`

Ajax:

   $(".deleteProduct").click(function(){
        var id = $(this).data("id");
        var token = $(this).data("token");
        $.ajax(
                {
                    url: "/admin/portfolio/settings/category/delete/"+id,
                    type: 'DELETE',
                    dataType: "JSON",
                    data: {
                        "id": id,
                        "_method": 'DELETE',
                        "_token": token
                    },
                    success: function ()
                    {
                        console.log("it Work");
                    }
                });

        console.log("It failed");
    });

Delete button:

 <button class="deleteProduct" data-id="{{ $category->category_id }}" data-token="{{ csrf_token() }}" >Delete Category</button>

Delete function:

public function destroy(Request $request, $id)
{
    Category::find($id)->delete();

    return response()->json([
        'success' => 'Record has been deleted successfully!'
    ]);
}
  • 写回答

1条回答 默认 最新

  • dpu66046 2016-10-11 11:20
    关注

    Either your Controller or Model has some error. May be syntax error. Try checking Console > Network > XHR. The error ajax request will be in red color if you are using Google Chrome.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集