如何使用react js在Fetch API中设置超时 | 您所在的位置:网站首页 › ajax请求超时时间设置无效 › 如何使用react js在Fetch API中设置超时 |
我在react js中使用了fetch post方法,当向后端发送请求时,需要7分钟才能提供响应,并且在前端自动超时之前。你能帮我解决一下如何在fetch方法中设置10分钟的时间,让前端等待响应,只有当后台花费超过10分钟时才会超时。如果我必须安装任何依赖项,请让我们知道。 我还想通知你,我已经安装了依赖项"whatwg-fetch-timeout":"^2.0.2-timeout“,它在开发服务器上工作得很好,但当尝试创建构建包时,它无法创建构建。示例代码: 代码语言:javascript复制fetch("http://" + hostName + ":" + port + "/searchData", { method: "POST", headers: { "Content-Type": "application/json", Login: login, ID: id }, body: JSON.stringify({ StartDate: StartDate === "" ? null : StartDate, EndDate: EndDate === "" ? null : EndDate, FileName: FileName === "" ? null : FileName, RecordCount: RecordCount === "" ? null : RecordCount, Status: Status }) }) .then(response => { resStatus = response.status; return response.json(); }) .then(responseJson => { //source code }) .catch(error => {}); |
CopyRight 2018-2019 实验室设备网 版权所有 |