1
我正在使用Slim框架+ Eloquent ORM。我想用ajax请求删除记录。唯一的问题是,当我按下按钮来触发请求时,我得到了405(方法不允许)错误。我的路线是删除路线,我已经将类型设置为DELETE以及如何使用带有Eloquent ORM的AJAX删除记录?
什么,我有我的AJAX请求至今:
$(".deleteYell").click(function(){
var id = $(this).data("id");
token = $(this).data("token");
$.ajax(
{
url: "/yell/"+id,
type: 'DELETE',
dataType: "JSON",
data: {
"id": id,
"_method": 'DELETE',
"_token": token,
},
success: function()
{
console.log("it Work");
}
});
console.log("It failed");
});
我的路线如下:
$this->delete('/yell/{id}', 'UserController:deleteYell')->setName('deleteYell');
,这里是用来删除该帖按钮:
<button class="deleteYell" data-id="{{ post.id }}" data-token="{{ csrf }}" type="button" name="button">Delete</button>
我应该为此换个工作?
你确定你包含路由文件吗? – jmattheis
你在'$ app-> group(..)'中有这条路线吗?你能证明一下吗? – jmattheis