gpt4 book ai didi

javascript - Internet Explorer 7 Ajax 链接只加载一次

转载 作者:可可西里 更新时间:2023-11-01 01:47:52 25 4
gpt4 key购买 nike

我正在编写一个应用程序,并试图将简单的 AJAX 功能绑定(bind)到其中。它在 Mozilla Firefox 中运行良好,但在 Internet Explorer 中有一个有趣的错误:每个链接只能单击一次。浏览器必须完全重启,简单地重新加载页面是行不通的。我写了一个 very simple example application这证明了这一点。

Javascript 转载如下:

var xmlHttp = new XMLHttpRequest();

/*
item: the object clicked on
type: the type of action to perform (one of 'image','text' or 'blurb'
*/
function select(item,type)
{

//Deselect the previously selected 'selected' object
if(document.getElementById('selected')!=null)
{
document.getElementById('selected').id = '';
}
//reselect the new selcted object
item.id = 'selected';

//get the appropriate page
if(type=='image')
xmlHttp.open("GET","image.php");
else if (type=='text')
xmlHttp.open("GET","textbox.php");
else if(type=='blurb')
xmlHttp.open("GET","blurb.php");

xmlHttp.send(null);
xmlHttp.onreadystatechange = catchResponse;

return false;

}
function catchResponse()
{
if(xmlHttp.readyState == 4)
{
document.getElementById("page").innerHTML=xmlHttp.responseText;
}

return false;
}

如有任何帮助,我们将不胜感激。

最佳答案

发生这种情况是因为 Internet Explorer 忽略了 no-cache 指令,并缓存了 ajax 调用的结果。然后,如果下一个请求相同,它将只提供缓存版本。有一个简单的解决方法,那就是在查询末尾附加随机字符串。

 xmlHttp.open("GET","blurb.php?"+Math.random();

关于javascript - Internet Explorer 7 Ajax 链接只加载一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/244918/

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