我已经设置好我的tomcat7 web服务器中的CORS,以便能够从另一个webapp获取我的xml文件。我面临的问题是如果我更改XML文件的内容,当我刷新浏览器时,它不显示更改,我必须重新启动服务器才能看到更改。如何使我的浏览器无需刷新即可显示更改?
我想知道我该如何解决它。另外,是否可以在不刷新浏览器的情况下获得更改?
<html>
<body>
<h1>W3Schools Internal Note</h1>
<div>
<b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span>
</div>
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://localhost:8080/test-app/note.xml",true);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.getElementById("to").innerHTML=
xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=
xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=
xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
</script>
</body>
</html>
你确定服务器端没有缓存吗? – adeneo 2013-03-19 03:31:55
如何检查是否有缓存? – 2013-03-19 03:33:43
首先按ctrl-f5重新加载而不在浏览器中进行缓存,看看是否是问题所在。如果不是,请检查该文件的标题,然后看到您在服务器上设置了某种缓存? – adeneo 2013-03-19 03:40:04