reactjs - 等待后不运行
问题描述
在第一次等待代码停止运行后,这是我的代码:
handleSubmit = async e => {
e.preventDefault();
const { name, number, email, message } = this.state;
try {
await axios.post("http://localhost:3001/send", {
name,
number,
email,
message
});
} catch (ex) {
this.setState({ result: "There was an error, try again." });
}
try {
const response = await fetch("http://localhost:3001/result");
const data = await response.json();
this.setState({ result: data });
} catch (ex) {
this.setState({ result: "There was an error, try again." });
}
};
但是第二次尝试中的第二次等待不起作用。有人能帮我吗
解决方案
我在我的节点代码中找到了解决方案,我将 res 放在同一个 url (.../send) 并且它有效
推荐阅读
- php - Laravel Passport JWT 身份验证失败
- c# - 为什么最初为所有数组列表项调用 CellValueNedded
- git - 为什么 git clean 和 reset 会留下文件?
- python - 在 heroku 上使用 eventlet 部署 Flask Socket.io 应用程序
- circuit-sdk - USER.SUBMIT_FORM_DATA:UPDATE Outgoing WebHook 调用的事件过滤器失败
- c++ - 嵌套内部类访问外部类
- typescript - TypeScript 和 redux 工具包,createSlice:分配给函数参数“状态”的属性
- android - 如何在适用于 Android 的 Moonreader 应用程序中的谷歌 tts 的 TTS 字符过滤器中的逗号前添加暂停
- c - kill会被信号打断吗?
- javascript - 如何在Javascript中获取另一个城市的当地时间