一: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中)