【问题标题】:Front doesn't send anything前台不发送任何内容
【发布时间】: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 的放置位置吗?

标签: mysql node.js angular


【解决方案1】:

好的,我解决了我的问题。

我改了地址

router.put('/update-status', (req: Request, res: Response)

router.put('/update-status/:id', (req: Request, res: Response)

我不明白为什么现在它可以工作,但无论如何感谢@Ms.Tamil 和@JDunken 的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    相关资源
    最近更新 更多