===都是缓存惹的祸=====

10 篇文章 0 订阅

一、用AJAX访问数据时的问题。

下面是ajax代码:

<script language="javascript" type="text/javascript">
var xmlHttp;
var popWindow;
function createXMLHttpRequest()
{
  if(window.ActiveXObject)
  {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if(window.XMLHttpRequest)
  {
    xmlHttp=new XMLHttpRequest();
  }
}
function doRequestUsingGET()
{
    createXMLHttpRequest();
     var queryString="Pop/CheckNewCaller.aspx?Channel=<%=Channel %>";
     //alert(queryString);
     xmlHttp.onreadystatechange=handleStateChange;
     xmlHttp.open("GET",queryString,true);
     xmlHttp.send(null);
}
function handleStateChange()
{
  if(xmlHttp.readyState==4)
  {
    if(xmlHttp.status==200)
    {
      //document.getElementById("temp").innerHTML +=xmlHttp.responseText + ",";//<iframe src="Pop/CheckNewCaller.aspx" width="0" height="0"></iframe>
      //alert(xmlHttp.responseText);   
            if(xmlHttp.responseText!="a")
            {
                popWindow= window.open("Pop/PopWindow.aspx?Phone=" + xmlHttp.responseText,'CCPop',"width=600,height=419,left=200,top=100");
                popWindow.focus();
            }
    }
  }
}
setInterval("doRequestUsingGET()",2000);
</script>

上面代码循环访问CheckNewCaller.aspx 下面是CheckNewCaller.aspx页的返回值的代码:

protected void Page_Load(object sender, EventArgs e)
    {
        Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);//禁止页面缓存

        if (Application["Caller"] != null && Request.QueryString["Channel"] != null)
        {
            DataTable dt = ((DataSet)Application["Caller"]).Tables["Caller"];
            string channel = Request.QueryString["Channel"].ToString();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["Channel"].ToString() == channel)
                    {
                        Response.Write(dt.Rows[0]["Phone"].ToString());
                        dt.Rows.Remove(dr);
                        Response.End();
                    }
                }
            }
            else
            {

                Response.Write("a");
                Response.End();
            }
        }
        else
        {

            Response.Write("a");
            Response.End();
        }
    }

页面运行后,不管DataSet里有没有值,总是返回a,有时过了几分钟了才返回正确的值,经查,是页面缓存的事。加上Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);//禁止页面缓存  才正常了。

二、xmldatasource  的缓存

 

string faxFiles = "<FaxFiles>";
            string faxPath = ConfigurationManager.ConnectionStrings["FaxPath"].ConnectionString + "Client//" + Session["ClientID"].ToString();
            DirectoryInfo di = new DirectoryInfo(faxPath);
            FileInfo[] fis = di.GetFiles("*.tif");

            int i = 1;
            foreach (FileInfo fi in fis)
            {
                faxFiles = faxFiles + "<Fax Serial='" + i++ + "' FileName='" + fi.Name + "' FileSize='" + fi.Length + "' UploadTime='" + fi.LastWriteTime.ToString() + "'/>";
            }

            faxFiles += "</FaxFiles>";

            xdsFax.Data = faxFiles;

 

上面的代码读取文件夹里的文件,绑定到DataView上。可是删除了一个文件后,还是显示在DataView上。在页面上和代码里设置页面缓存根本就没有用。必须给xmldatasource的EnableCaching 属性 设置为 false才可以。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值