我正在尝试使用AJAX调用来删除我的配方应用程序中的评论.
它一直给我一个405错误:不允许使用方法.不知道它在哪里破裂,对我来说看起来还不错.有人可以看看吗?
刀片视图
@foreach($recipe->comments as $comment)
@if($comment->name == Auth()->user()->name)
{{$comment->comment}}
Delete Comment
@else
@endif
@endforeach
自定义js文件
// Delete Comments AJAX
$(".deleteComment").click(function(){
var id = $(this).data("id");
var token = $(this).data("token");
$.ajax(
{
url: "/comment/delete/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": token,
},
success: function ()
{
console.log("it Work");
}
});
console.log("It failed");
});
路线
Route::delete('comment/delete/{id}', 'CommentsController@destroy');
CommentController @ destroy
public function destroy($id)
{
Comment::destroy($id);
return redirect()->back();
}
有人能看到它在哪里破裂吗?