专注于高品质PHP技术等信息服务于一体 [STIEMAP] [RSS]

百度提供的广告:
PHP
当前位置:首页 > 技术文档 > PHP >  > 
IE浏览器下Ajax 请求,缓存bug

IE浏览器下Ajax 请求,缓存bug
解决方法,
1,以后面加一个随机参数 或者使用jquery $.ajax中不带缓冲的加载方法,其原理也是在后面加了一个随机参数
2,在服务器 response中设置 header即可。

public void ProcessRequest (HttpContext context) {
        context.Response.AddHeader("Pragma", "no-cache");
        context.Response.AddHeader("Cache-Control", "no-cache");
        context.Response.AddHeader("Expires", "0");
        context.Response.ContentType = "text/plain";
        Random r = new Random();
        String str=r.Next(1000).ToString();
        context.Response.Write(str);
    }
经测试,IE8下正常。
参阅 php 织梦CMS include common.func.php

function AjaxHead()
{
    @header("Pragma:no-cache\r\n");
    @header("Cache-Control:no-cache\r\n");
    @header("Expires:0\r\n");
}