angular - 角度 http 帖子从不调用后端操作
问题描述
我正在尝试向我的节点后端执行 http 发布。Todo 所以我尝试了这种方法(通过单击材料底页中的按钮触发)
return this.http.post<any>('http://localhost:5000/location/addreview', JSON.stringify({
username: this.data.username,
ts: Date.now(),
userid: this.data.userid,
rate: this.currentRate,
message: this.message,
restId: this.data.locId
})
);
这是我的后端:
router.post('/addreview', async(req, res) => {
console.log("called")
const username = req.body.username;
const userid = req.body.userid;
const ts = req.body.ts;
const rate = req.body.rate;
const message = req.body.message;
const restaurantId = req.body.restId;
collection.update(
{ _id: ObjectId(restaurantId) },
{ $push: { reviews: { username: username,
rate: rate,
ts: ts,
userid: userid,
message: message } } }
)
res.end("Review saved");
res.status(200);
}
})
被调用的打印从未被调用,所以我认为该帖子从未被执行
解决方案
推荐阅读
- c++ - c++:通过引用传递二维数组?
- php - Laravel 和 React Native 可以分开工作吗?
- android - 删除容器之间的线条(颤动/飞镖)
- python - 设置/重置在 __main__ 中的 __init__ 中声明和初始化的变量的值
- flutter - 如何使用颤振在 Listview rom API 上添加项目
- powershell - Active Directory AccountExpiresDate 比较
- r - R - 如何让 choose.dir() 使用 windows 文件资源管理器,如 choose.files()
- android - 如何在 textview 文本中添加“软”换行符
- amazon-s3 - 使用 field_optionally_enclosed_by 参数复制 CSV 数据时遇到问题
- javascript - 如何在JS中读取数组中的存储值