代码之家  ›  专栏  ›  技术社区  ›  Muhammad Muazzam

错误:内部服务器错误Laravel 5.4 ajax调用

  •  0
  • Muhammad Muazzam  · 技术社区  · 7 年前

    id

    $.ajax({
        url:'/delprofile',
        type: 'delete',
        data: {  
           id: 5,
           '_token': $('meta[name="csrf-token"]').attr('content')
        },
        success: function(){ alert("Record deleted.") },
        error: function(jqXHR, textStatus, errorThrown) {
          console.log(textStatus + ' : ' + errorThrown);
        }
    });
    

    Laravel函数:

    Route::delete('/delprofile','ProfileController@delprofile');
    
    public function delprofile (Request $request){
       $id=$request->input('id');
       DB::table('education')->where('id','=',id)->delete();
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Sletheren    7 年前

    身份证件 是一个变量, $id id

    此外,为了获得更好的代码:

    1-在AJAX调用中指定方法作为标准 "POST"

    2-将其添加到数据中: _method: 'delete' 因为这是推荐的发送方式 删除 补丁 放置

    3-添加 return response()->json($id); 以确保已成功发送ID。

    success: function(data){console.log(data); alert("Record deleted.")....