使用jquery的ajax来发送请求进行局部刷新画面,各位可能都做过。
今天碰到一个奇怪的现象,就是,同一个ajax请求,在chrome中,不论发送多少次,都可以发送至服务器端,而不会被缓存。但是,换成在IE下的时候,发现,同一个ajax请求,会发生被缓存的情况,只有第一次才会被发送至服务器端,之后的不会再被发送。郁闷。
解决方法如下:
① 直接使用 JQuery提供的 “cache”参数,将其修改为false,即如下(第四行):
$.ajax({
'url' : contextPath + '/file!getAllMajor',
'type' : 'get',
'cache' : false,
'dataType' : 'json',
'async' : true,
'success' : function(data, status, xhr) {
// xxxxx
},
'error' : function(xhr, status, error) {
// xxxxx
}
});② 这种方案是经常使用的,就是在URL后面添加一个随机数,即如下:
$.ajax({
'url' : contextPath + '/file!getAllMajor?' + Math.random(),
'type' : 'get',
'dataType' : 'json',
'async' : true,
'success' : function(data, status, xhr) {
// xxxxx
},
'error' : function(xhr, status, error) {
// xxxxx
}
});