zoukankan      html  css  js  c++  java
  • cache -- clear( 缓存清除的方法)

    一:meta方法

    <META HTTP-EQUIV="pragma" CONTENT="no-cache"> 
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"> 
    <META HTTP-EQUIV="expires" CONTENT="0">

    二:清理form表单的临时缓存 
    方式一:用ajax请求服务器最新文件,并加上请求头If-Modified-Since和Cache-Control,如下:

     $.ajax({
         url:'www.haorooms.com',
         dataType:'json',
         data:{},
         beforeSend :function(xmlHttp){ 
            xmlHttp.setRequestHeader("If-Modified-Since","0"); 
            xmlHttp.setRequestHeader("Cache-Control","no-cache");
         },
         success:function(response){
             //操作
         }
         async:false
      });

    方法二,直接用cache:false

     $.ajax({
         url:'www.haorooms.com',
         dataType:'json',
         data:{},
         cache:false, 
         ifModified :true ,
    
         success:function(response){
             //操作
         }
         async:false
      });

    方法三:用随机数,随机数也是避免缓存的一种很不错的方法!

      

    URL 参数后加上 "?ran=" + Math.random(); //当然这里参数 ran可以任意取了
    eg:
    <script> 
    document.write("<s"+"cript type='text/javascript' src='/js/test.js?"+Math.random()+"'></scr"+"ipt>"); 
    </script>
    
    其他的类似,只需在地址后加上+Math.random() 
    注意:因为Math.random() 只能在Javascript 下起作用,故只能通过Javascript的调用才可以 

    三:后端清理

      在服务端加 header("Cache-Control: no-cache, must-revalidate");等等(如php中)

  • 相关阅读:
    C# 泛型
    css样式优先级
    c# 可空类型
    JS 两个数组合并
    c# 参数传递问题(形参与实参)
    c# JsonReader读取json字符串
    C# 获取当前ip
    swprintf引发的血案
    Struts2解析FreeMarker模板中变量的顺序
    structs2在action中输出
  • 原文地址:https://www.cnblogs.com/yuerdong/p/8241475.html
Copyright © 2011-2022 走看看