勤于思考:jquery.getJSON的缓存问题的解决方法

在项目中遇到一个问题,在火狐下,$.getJSON();请求数据一切正常,但是在IE下面,$.getJSON();只请求一次数据,第二次根本就不发送请求了,用fiddler抓取了才知道,第二次没有发送请求,改成了post就正常了

$.getJSON()存在缓存问题,如果其调用的url之前曾经调用过的话,回调函数就会直接在缓存里面取得想要得值,而不是进入到后台

解决方法如下:

1、让每次调用的URL都不一样。

方法:在参数中加一个随机数

$.getJSON("/Member/GetExercise.html", { id: $("#Wareid").val(), isBool: loop, random: Math.random() }, function (data) });
$.getJSON("/Member/GetExercise.html?random=Math.random", { id: $("#Wareid").val(), isBool: loop,}, function (data) });

用new Date()也可以算是随机的URL

?random=new Date().getTime()

2、将cache设为false

$.ajax({
type:"GET",
url:'/Member/GetExercise.html',
cache:false,
dataType:"json",
success:function (data){
alert(data);
}
});

 或者声明meta标签

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expries" content="-1">
原文地址:https://www.cnblogs.com/79039535/p/2988564.html