【发布时间】:2018-05-08 13:07:11
【问题描述】:
使用 Fetch API 我发送以下请求:
const target = e.currentTarget;
fetch(target.href, {
method: 'delete',
})
.then(res => console.log(22))
.catch(err => console.log(err));
另外,这是处理这个请求的中间件:
exports.deleteImageById = async (req, res) => {
const image_id = req.params.image_id;
const imagePromise = Image.findByIdAndRemove(image_id);
const commentPromise = Comment.remove( {image_id} );
await Promise.all([imagePromise, commentPromise])
.catch(err => console.log(err));
req.flash('Image Deleted!');
// return something well!
res.status(200);
};
正在删除文档,但 fetch 语句中的 then 块不起作用。它不会向控制台输出任何内容。
我在这里做错了吗?
【问题讨论】:
标签: javascript node.js ajax express fetch