gpt4 book ai didi

javascript - 使用超时在 JavaScript 中请求 POST

转载 作者:行者123 更新时间:2023-11-30 20:21:44 25 4
gpt4 key购买 nike

我想发送这样的请求:

$.ajax({
type: "POST",
url: url,
data: data,
success: function(data) {
console.log(data);
var file = new Blob([data], {
type: 'application/zip'
});
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
},
error: function(xmlhttprequest, textstatus, message) {
if (textstatus === "timeout") {
alert("got timeout");
} else {
alert(textstatus);
}
},
timeout: 10000
});

但是超时时间还不够。我在 Java 服务器中遇到错误:

Try to write on a closed channel[keepAlive:true]: Remote host may have closed the connection

有没有一种方法可以使连接保持打开状态直到得到答案?

谢谢

最佳答案

将超时设置为0表示无限制,默认为0,但有些浏览器有自己的超时时间。我希望您也知道超时以毫秒为单位,所以您只等待 10 秒,如果 timeout: 0 不起作用,可以尝试将其增加到大约 60 秒 (60000)

关于javascript - 使用超时在 JavaScript 中请求 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51384076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com