[英]How to use AJAX with Eloquent ORM to delete records?
I'm using Slim framework + Eloquent ORM. 我正在使用Slim框架+雄辩的ORM。 I want to delete records with an ajax request. 我想用ajax请求删除记录。 Only problem is that when I press the button to trigger the request, I get a 405 (method not allowed) error back. 唯一的问题是,当我按下按钮触发请求时,我收到了405(不允许使用的方法)错误。 My route is a delete route and I've set the type to DELETE as well 我的路线是删除路线,我也将类型设置为DELETE
what I have for my AJAX request so far: 到目前为止,我对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");
});
my route is as follows: 我的路线如下:
$this->delete('/yell/{id}', 'UserController:deleteYell')->setName('deleteYell');
and here's the button that is used to delete the post: 这是用于删除帖子的按钮:
<button class="deleteYell" data-id="{{ post.id }}" data-token="{{ csrf }}" type="button" name="button">Delete</button>
What should I change for this to work? 我该如何更改才能正常工作?
You have to use POST method.give it a try 您必须使用POST方法。尝试一下
$(".deleteYell").click(function(){
var id = $(this).data("id");
token = $(this).data("token");
$.ajax(
{
url: "/yell/"+id,
type: 'POST',
data: {
"id": id,
"_method": 'DELETE',
"_token": token,
},
success: function ()
{
console.log("it Work");
}
});
console.log("It failed");
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.