Ajax和IE缓存。网上能找到的方法全试了,就是不行。
CIT 2007-12-29 02:06:24 网上找到的方法
url接上随机数字或者日期
客户端禁止缓存
服务器端禁止缓存
都无效
firefox2.0 IE7.0 apache2.0 PHP5.2.5 mysql 5.0
firefox一切正常,就是IE只能发送一次请求,除非刷新页面才能再发送一次。
以下是javascirpt的代码
//ajax创建
function InitAjax()
{
var ajax=false;
if(window.ActiveXObject){
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.ActiveXObject){
ajax = new ActiveXObject("Msxml2.XMLHTTP.4.0");
}else if(window.ActiveXObject){
ajax = new ActiveXObject("Msxml2.XMLHTTP");
}else if(window.XMLHttpRequest){
ajax = new XMLHttpRequest();
}
return ajax;
}
//生成ajax对象
var ajax = InitAjax();
//call函数
function RegUserID()
{
var str = document.getElementById("f_UserID").value;
var div = document.getElementById("d_RegUserID");
if(!UserIDCheck(str))
{
div.innerHTML = "帐号格式非法";
return false;
}
else
{
var url = "bc/bc_useridcheck.php?UserID="+str+"&date="+new Date().getTime()+"&rand="+Math.random();
ajax.onreadystatechange = UserIDAjax;
var PostStr = "UserID="+str;
ajax.open("GET",url,true);
ajax.setRequestHeader("If-Modified-Since","0");
ajax.send(null);
}
}
//服务器端PHP页面
<?php
header("Cache-Control: no-cache, must-revalidate");
mb_http_input("utf-8");
mb_http_output("utf-8");
$path=dirname(__FILE__);
include_once $path.'/../../../oa/oa_db_general.php';
include_once $path.'/../../../oa/oa_db_result_operator.php';
$UserID = $_GET['UserID'];
$mydb = new OADBGeneral('cdtc');
$strsql = "select ID from userinfo where UserID='".$UserID."'";
$res = $mydb->ExecSQL($strsql);
$result = new OADBResultOperator($res);
$num = $result->GetRecordCount();
if($num == 0)
echo "1";
else
echo "0";
?>