【发布时间】:2020-06-03 05:52:12
【问题描述】:
数据已成功删除,但我收到错误代码 GET http://localhost:3000/api/deletetagbyid/5e4d896cea390804241612cd 404 (Not Found)。
任何人都可以帮助我实际上我是反应节点的新手:- 谢谢你
// Delete Discount Tag Using Axios :-
const handleDelete = async (e, id) => {
if (confirm("Are you sure. You Want to delete this tag?")) {
await axios.get("/api/deletetagbyid/" + id).then((result) => {
console.log(result);
}).catch(() => {
console.log('Error Occured');
});
}
}
// This is the backend code to delete data with koa js :-
exports.deletetagbyid = (ctx) => {
let id = ctx.params.id;
Note.findOne({
"_id": ObjectID(id)
}, function (err, docs) {
if (!docs) {
ctx.body = 404;
} else {
Note.deleteOne({
_id: id
}, function (err, obj) {
if (err) throw err;
ctx.body = "Deleted SuccessFully";
console.log(" document(s) deleted");
});
}
})
};
// This is the route for delete data :-
router.get('/api/deletetagbyid/:id', discounttag.deletetagbyid);
【问题讨论】:
标签: node.js reactjs mongodb koa