【发布时间】:2021-09-02 10:36:52
【问题描述】:
多年来我一直在尝试自己解决这个问题,但我已经放弃了。我正在使用 React 和 Node:
- 从 React 向 Node 发送文本
- 修改Node中的文字
- 将修改后的文本发送回 React
如果我单击启动 POST 请求,等待一秒钟,然后单击另一个按钮启动 GET 请求,一切正常,但我试图通过一个命令完成所有操作。我的问题是 GET 请求通常先完成,所以我的问题是:如何确保 POST 请求在 GET 请求开始之前完成。
我试过了,但没有用:
postReq = () => {
if(this.state.theUrl.length > 0) {
axios.post('http://localhost:5000/check', {
url: this.state.theUrl
}).then(function(response) {
console.log("Success")
}).catch(function(error) {
console.log(error)});
}
else {
return 1;
}
return "Finished"
}
getReq = () => {
axios.get('http://localhost:5000/check')
.then((getResponse) => {
this.setState({summaryParts: getResponse.data, postResponse: ""})});
};
callApi = async() => {
const result = await this.postReq();
this.getReq();
}
【问题讨论】:
-
你能分享一下
postReq的样子吗
标签: reactjs express asynchronous async-await