gpt4 book ai didi

javascript - XMLHTTP ReadyState 3 未在 Webkit 中更新

转载 作者:行者123 更新时间:2023-11-28 09:28:19 30 4
gpt4 key购买 nike

这个问题已在这些论坛上被问过两次,但提供的答案对我不起作用。

问题是我的 JSP 页面正在返回并刷新少量输出。

我使用以下代码来读取输出:

var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 3) {
alert(xmlhttp.responseText);
}
}

xmlhttp.open("POST", "download.jsp", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader('X-Requested-With', "XMLHttpRequest");
xmlhttp.send($('#submitDownloadForm').serialize());

在 Firefox 上,这工作正常,并且在此过程期间我收到了 3 个警报。

但是,在基于 Webkit 的浏览器(例如 Chrome 和 Safari)上,我会收到第一个警报,但在该过程完成之前不会收到其他两个警报。

其他答案表示更改 Content-Type:text/plainContent-Type:application/octet-stream,但如果我这样做,readyState 直接跳转到 4,就好像该过程立即完成一样。

我找不到任何解决方案。

非常感谢任何帮助,提前感谢大家。

最佳答案

我将以下代码添加到 JSP 文件中生成输出的位置之前,这解决了基于 Webkit 的浏览器上的问题:

response.setContentType("application/octet-stream");

现在,每次刷新输出时我都会收到更新。

关于javascript - XMLHTTP ReadyState 3 未在 Webkit 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14011755/

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