在项目中遇到一个问题,在火狐下,$.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);
}
});
Stellungnahme:Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn