一、用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才可以。

 

 


本文转载:CSDN博客