本文介绍了Internet Explorer 7中的Ajax的联系只加载一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,我想配合简单的AJAX功能,它的工作原理以及在Mozilla Firefox,但有在Internet Explorer中一个有趣的错误:每个链接只能使用一次点击。浏览器必须完全重新启动,只需重新加载页面将无法正常工作。我写了一个非常简单的示例应用程序演示此。

I'm writing an application and I'm trying to tie simple AJAX functionality in. It works well in Mozilla Firefox, but there's an interesting bug in Internet Explorer: Each of the links can only be clicked once. The browser must be completely restarted, simply reloading the page won't work. I've written a very simple example application that demonstrates this.

使用Javascript转载如下:

Javascript reproduced below:

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;
}

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

这是因为Internet Explorer中忽略了no-cache指令,并缓存的AJAX调用的结果。然后,如果下一个请求是相同的,它只会起到了缓存版本。有一个简单的解决方法,那就是只追加随机字符串您的查询的末尾。

This happens because Internet Explorer ignores the no-cache directive, and caches the results of ajax calls. Then, if the next request is identical, it will just serve up the cached version. There's an easy workaround, and that is to just append random string on the end of your query.

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

这篇关于Internet Explorer 7中的Ajax的联系只加载一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 03:27