ajax之cache血与泪~~
场景:项目以ie5渲染页面,点击导出列表数据(Excel形式),点击导出发送get请求,后台生成Excel文件,返回文件地址信息
异常:ie第一次返回的信息正常,之后返回的都是第一次的结果,google正常
后台方法断点,ie只有第一次会进断点,之后没有进断点
异常代码:
| 
            1 
           
            2 
           
            3 
           
            4 
           
            5 
           
            6 
           
            7 
           
            8 
           
            9 
           
            10 
           
            11 
           
            12 
           
            13 
           
            14 
           
            15 
           
            16 
           
            17 
           | alert(1);$.ajax({url: actionURL +"?"+ $.param({Action: 
             "export",strWhere: strwhere}), 
            data: { page: page,rows: rows },type: 
             "get" 
            alert(data); 
            window.location.href ="../../Views/MEAS/Download.aspx?filePath="+ escape(data);}, 
            error:(e) {alert(e); 
            }}); 
            | 
解决方案:1.加cache:false
2.url加随机数
正常代码:
alert(1); $.ajax({ url: actionURL + "?" + $.param({ Action:"export",strWhere: strwhere }),data: { page: page,type: "get",cache:false, success: function (data) { alert(data); window.location.href = "../../Views/MEAS/Download.aspx?filePath=" + escape(data); },error: function (e) { alert(e); } });
网上高人解读:
cache的作用就是第一次请求完毕之后,如果再次去请求,可以直接从缓存里面读取而不是再到服务器端读取。 如果使用jquery,可以使用cache参数来控制 $.ajax({ url:"test.html",cache:false,//或者设置true success:function(html){ $("#results").append(html); } });