我想使用jQuery ajax删除数据,但是它不起作用。 任何人都可以提出建议,为什么它不起作用或哪里有问题
HTML代码:
<a href="" class="delete-evidance" class="btn btn-outline-danger my-2 my-sm-0">Delete</a>
jQuery代码:
$(".delete-evidance")({
url: "/goal/delete/evidance._id/data._id",
ajaxOptions: {
dataType: "json"
},
success: (data, config) => {
const res = data.responseJSON;
$.bootstrapGrowl(
`<h4>Successfully Deleted!</h4><p>${res.returnObject.msg}</p>`,
{
type: "warning",
delay: 3500,
allow_dismiss: true
}
);
return `Error\n${res.returnObject.msg}`;
}
});
nodejs控制器代码(此代码只是为了知道后端发生了什么):
var evidanceDelete = function(req, res, next) {
const updateObj = {
$pull: {
evidance: {
_id: req.params.evidanceId
}
}
};
答案 0 :(得分:0)
$('.delete-evidance').click(function () {
$.ajax({
url: '/goal/delete/evidance._id/data._id',
ajaxOptions: {
dataType: 'json'
},
success: (data, config) => {
const res = data.responseJSON;
$.bootstrapGrowl(
`<h4>Successfully Deleted!</h4><p>${res.returnObject.msg}</p>`,
{
type: 'warning',
delay: 3500,
allow_dismiss: true
}
);
return `Error\n${res.returnObject.msg}`;
}
})
});