Java 如何让XMLHttpRequest在IE中不死板
你好,, 我有以下问题(代码可以正常工作),当我使用firefox或Chrome时,xmlhttpRequest(ajax调用)会重新引用(因此它工作得很好)。但是IE 9.0+缓存了XMLHttprequest,因此它从不重新格式化。我在网上读了很多关于这个问题的文章,但是我真的找不到任何解决这个问题的方法 有人能告诉我解决这个问题的可能性吗? 我认为使用jQueryAjax是可以修复的,但我没有足够的头脑将整个脚本调整到jquery中。有人说你可以将实时时间设置为0,但我找不到这个。(我用servlet与Ajax通信) 有人知道一个清晰、简单的解决方案吗Java 如何让XMLHttpRequest在IE中不死板,java,javascript,jquery,ajax,xmlhttprequest,Java,Javascript,Jquery,Ajax,Xmlhttprequest,你好,, 我有以下问题(代码可以正常工作),当我使用firefox或Chrome时,xmlhttpRequest(ajax调用)会重新引用(因此它工作得很好)。但是IE 9.0+缓存了XMLHttprequest,因此它从不重新格式化。我在网上读了很多关于这个问题的文章,但是我真的找不到任何解决这个问题的方法 有人能告诉我解决这个问题的可能性吗? 我认为使用jQueryAjax是可以修复的,但我没有足够的头脑将整个脚本调整到jquery中。有人说你可以将实时时间设置为0,但我找不到这个。(我用s
非常感谢一种公认的做法是向url添加一个随机参数,如时间戳 在url中添加一个参数,如
\u d
,其值为new Date().getTime()
例:
阿伦P约翰尼,再次感谢你的回答!真的很完美
if(xmlhttp) {
xmlhttp.open("GET","DokterWeek_KlantoverzichtServletAjax?" + $(this).prop("href").split("?")[1],true);//gettime will be the servlet name
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(null);
}
});
});
function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera,chrome Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}
var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object
function handleServerResponse() {
document.getElementById("pop1").innerHTML = xmlhttp.responseText; //Update the HTML Form element
}
xmlhttp.open("GET","DokterWeek_KlantoverzichtServletAjax?_d=" + (new Date().getTime()) + '&' + $(this).prop("href").split("?")[1], true);//gettime will be the servlet name