【发布时间】:2018-07-13 19:19:44
【问题描述】:
我正在尝试对 NodeJS 服务器进行 jQuery ajax 调用,然后服务器将轮询另一个端点,最长 2 分钟。
不幸的是,就在服务器完成 POLLING 并即将响应 jQuery ajax 后,连接被终止。
我如何才能让这条路线的连接保持 2 分钟,而不是每条路线。这是我现在的 AJAX 帖子:
$.ajax({
url: $(this).attr("action"),
type: 'POST',
data: formdata,
processData: false,
contentType: false,
beforeSend: function(request) {
request.setRequestHeader("Keep-Alive", 'timeout=121, max=100')
},
success: function (res) {
if (res.status === 200) {
Materialize.toast(res.msg, 4000, 'green')
}
else {
Materialize.toast(res.msg, 4000, 'red')
}
},
error: function (xhr, status, error) {
Materialize.toast(error, 4000, 'red')
}
})
当我检查请求标头时,没有设置“Keep-Alive”,我错过了什么?
【问题讨论】:
标签: javascript jquery node.js ajax