use*_*452 5 javascript reactjs fetch-api
我在 React js 中有一个提取请求,它调用 API(Node js 后端服务器)。对于通过 Google Chrome 发出的任何耗时超过 2 分钟的请求,获取请求都会引发错误:
“获取失败”。
如果我传递的参数较少(即请求哪个服务器花费的时间少于 2 分钟),则它可以正常工作。
下面是我的代码。
fetch(url , requestOptions)
.then(response => response.blob())
.then(blob => {
const newBlob = new Blob( [blob], {type: 'application/zip'});
const downloadUrl = URL.createObjectURL(newBlob)
let a = document.createElement("a");
a.href = downloadUrl;
a.download = "reports";
document.body.appendChild(a);
a.click();
alert(this.state.selectedReport + "Reports Downloaded Successfully")
})
.catch((error) => {
alert("Error in downloading report " + error)
})
Run Code Online (Sandbox Code Playgroud)
通过网上浏览,发现fetch请求中没有超时参数。
我尝试使用等待和异步,但它没有成功,并且还从下面的链接中得到答案。
我想获取后端服务器花费超过2分钟的数据。谁可以帮我这个事?
小智 1
| 归档时间: |
|
| 查看次数: |
1144 次 |
| 最近记录: |