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.

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

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)