【发布时间】:2020-06-24 15:49:01
【问题描述】:
我尝试更新一个表,所以我将新数据从我的前面(Angular)发送到我的后面(Node)。当我 console.log 前面一切正常,但后面什么都没有发生。
但是,我的控制台验证了我的请求(奇怪的东西 PUT /tournaments/update-status 200 79.748 ms - 2, 最后总是有这个“- 2”)
但是,Back 可以在 Postman 上使用,我已经在项目的其他地方使用过这种方法,并且效果很好。
这是我前面的代码:
updateParticipantStatus(participant){
return this.http.put<Participant>(`${this.baseUrl}/tournaments/update-status`, participant)
.subscribe(result => result);
}
现在是后面:
router.put('/update-status', (req: Request, res: Response) => {
const participant: Participant = req.body;
tournamentsService.updateParticipantStatus(participant).then(result => {
res.send(result);
})
.catch(err => {
console.log(err);
})
});```
PS: Sorry for my bad english, if needed I can send more code.
【问题讨论】:
-
updateParticipantStatus 方法中参与者的值是多少?如果那不是字符串,则不能将其附加到 URL。
-
@Ms.Tamil Op 没有将
participant附加到 url,它是请求的负载。 -
我会在
.subscribe之前添加一个.pipe和一个.tap和一个.catchError,以确保我看到所有错误。 -
@Ms.Tamil:参与者是一个对象(id、comment、army_status)
-
@JDunken:抱歉,您能解释一下 .pipe、.tap 和 .catchError 的放置位置吗?