gpt4 book ai didi

javascript - 无缓存和更新在带有 JSP 和 Javascript 的 IE 10 中不起作用

转载 作者:行者123 更新时间:2023-11-30 12:45:49 25 4
gpt4 key购买 nike

我已关闭缓存并使用 javascript 从 jsp 页面中的 rest 调用手动检索状态。每个人都喜欢它(Chrome、FireFox、Safari、Opera),当然 IE 8-11 除外。

大部分工作由 getStatus() 完成。这使用 XMLHttpRequest 从 REST 调用中检索一组 json 状态。它解析 json 并将状态复制到 td 标签的 innerHTML。我使用 setInterval() 每 5 秒执行一次。

我使用靠近 jsp 顶部的 Cache-Control、Pragma 和 Expires header 关闭缓存。

症状是状态永远不会更新。

代码如下:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
//tell browsers and proxy servers not to cache this page
if ("HTTP/1.1".equals(request.getProtocol()))
{
response.setHeader("Cache-Control", "no-cache");
}
response.setHeader("Pragma","no-cache" );
response.setDateHeader("Expires", 0);
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Application Title</title>
<link rel="stylesheet" type="text/css" href="<c:out value="${pageContext.request.contextPath}"/>/css/Admin.css" />

<script type="text/javascript">
// need enough time for jbehave to parse the page
var REFRESH = 5000; // 5 seconds

// Update status after 5 seconds has elapsed.
setInterval("jobStatus();", REFRESH);

function jobStatus() {
getStatus();
}

function getStatus() {
var xhttpRequest = getXMLHttpRequest();
xhttpRequest.open("GET", "<c:out value="${pageContext.request.contextPath}"/>/admin/resyncPhs/getstatus", true);
xhttpRequest.onreadystatechange = function() {
if (xhttpRequest.readyState === 4) {
if (xhttpRequest.status === 200) {
var json = xhttpRequest.responseText;
var parsed = JSON.parse(json);

document.getElementById("status").innerHTML = parsed.status;
document.getElementById("progress").innerHTML = parsed.progress;
}
}
};
xhttpRequest.send(null);
}

function getXMLHttpRequest() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}

</script>

</head>
<body onLoad="jobStatus();">
<table class="resyncBodyTable">
<tr>
<td />
<td>Labels:</td>
<td id="status">${status}</td>
<td id="progress">${progress}</td>
</tr>
</table>
</body>
</html>

有什么线索吗?

最佳答案

IE 比其他浏览器需要更多说服力:

response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma","no-cache");

关于javascript - 无缓存和更新在带有 JSP 和 Javascript 的 IE 10 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22519397/

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