angular - 角度 PUT 请求未达到快速代码
问题描述
我的 app.js 后端完美地满足了我的需求。Postman 在测试时正确更新,但由于某种原因,角度 http PUT 请求未连接。我真的不知道为什么,因为路径是一样的。任何帮助表示赞赏。
错误:
"Http failure response for http://localhost:3000/api/user/email/5dc1b5bccghdc22788b30922: 0 Unknown Error"
角服务
const updateEmail: UserEmailChange = {
id: id, oldEmail: oldEmail, newEmail: newEmail
};
return this.http.put('http://localhost:3000/api/user/email/' + updateEmail.id, updateEmail, { headers: { 'Content-Type': 'application/json' } });
}
应用程序.js
app.put('/api/user/email/:id', (req, res) =>
User.update(
{email: req.body.oldEmail},
{email: req.body.newEmail}
).then( user => {
console.log(user);
res.json(user);
// res.sendStatus(200);
})
.then( user => {
console.log(user);
res.json(user);
// res.sendStatus(200);
}).catch(err => console.log(err)));
解决方案
您应该将 :id 替换为服务中的值。
推荐阅读
- ios - 使用 evaluateJavascript 方法在 WKWebview 上设置本地图像
- installation - 当我尝试安装 Cypress 时显示错误
- css - 为什么我的 nth-child 覆盖不能与我的引导网格一起使用?
- javascript - 如何在json层次结构中获取嵌套json对象的键
- abap - 仅生产中的 Abap 语法错误,但不是 dev/qa
- javascript - 返回未定义
- upgrade - 无法将 Couchbase 服务器社区版从 4.5 升级到 5
- javascript - Bootstrap / Blazor - 图片点击链接,点击没有任何反应
- javascript - 找出每个子数组中任意一个元素可以形成的最大乘积
- ansible - 使用 ansible _mount 和 json_jquery 的剧本任务引发错误