前端框架Bootstrap的Modal使用Ajax数据源,如何避免数据被缓存

1、绑定事件,在关闭的时候,直接将数据清除: 

Javascript代码  收藏代码
  1. $("#model").on("hidden.bs.model",function(e){$(this).removeData();});  


2、修改一下请求的url,添加随机参数,强制刷新,先用jQuery的get方法取内容,再放到modal中。如下: 
Javascipt代码  收藏代码
  1. function remoteUrl(u){  
  2.     u += '&t=' + Math.random(1000)  
  3.     $.get(u, '', function(data){  
  4.         $('#remoteModal .modal-body').html(data)  
  5.     })  
  6.     $('#remoteModal').modal({show:true,backdrop:false})  
  7. }  

3.加时间戳 var timestamp=new Date().getTime();

你可能感兴趣的:(前端框架Bootstrap的Modal使用Ajax数据源,如何避免数据被缓存)