javascript - 如何获取传入的状态响应?
问题描述
服务器完成工作后如何获取传入响应?(节点新手)正如您将在下面的代码中看到的那样,在我的中间件向用户发送电子邮件后,我正在向前端发送响应。通过这个我想知道服务器完成了它的工作,所以我可以向用户展示他可以去查看他的电子邮件!任何想法如何实现这个!如果我发送 JSON 页面会重新加载如果我发送状态我不知道如何获得确认我可以通过发送 cookie 来做到这一点,但这是个好主意?
感谢您提前付出的努力和时间
// Backend signup route "/sign"
//SignUp New User logic
exports.signUp = async (req, res, next) => {
const newUser = await User.create({
Email: req.body.Email,
Password: req.body.Password,
Password: req.body.PasswordConfirm
})
await sendEmail({
email: req.body.Email,
subject: 'Welcome new user',
})
//res.cookie("server has sent the email")
//res.status(200)
//next()
}
// Frontend Response
let request = fetch("/sign");
request
.then(response => {
const status = response.headers.get("status");
if (status == 401) {
// read 401 response
response.text().then(res => console.log(res));
return "404.html"
}
if (status == 200) {
return "200.html"
}
})
.then(result => console.log(result))
//.catch(err => // handle error);
解决方案
推荐阅读
- bash - if 语句条件失败并直接跳到 else 部分
- django - Django 频道 - websocket_disconnect 在循环中被调用
- r - 在正斜杠之前和之后提取数字之前/
- docker - 配置 Minio 服务器以与 Testcontainers 一起使用
- java - 有没有办法在 Java 中将类/方法声明为实验性的?
- python - 调用存储在结构内更高级别的嵌套结构中的 Python 脚本
- azure - 无法从 Microsoft Graph API 端点获得响应
- c++ - 视频拍摄中的图片和文字
- sql - 如何在 SQL 中仅从数据库中查询旧数据和重复数据
- java - Rijndael 实现中的 OutputLengthException