微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

神奇的IE9,Ajax请求缓存问题

如图所示:点击“发表评论”,发表一条商品评论

相关的代码如下:

//评价之前判断是否登录,如果已登录跳转到评价页面,如果没登陆提示登录
function judgeUserLogin(itemId,itemGroupId){
	$.ajax({
        url: shop_Path+"front/consult/judgeLogin.htm",type: 'POST',dataType: 'JSON',timeout: 5000,error: function() { },success: function(data) { 
	        if (data.result) {
	        	jConfirm("请登录后再对商品进行评价!","提示信息",function(r){
	        		if (r) {
	        			window.location.href = occweb_Path+"login.htm?redirect="+location.href;
	        		}
	      		  });
	        } else {
	        	addItemAppraisal(itemId,itemGroupId);
	        }
        }
  });
}

//新增评价
function addItemAppraisal(itemId,itemGroupId){
	var comment = $("#comment").val();
	$.ajax({
        url: shop_Path+"front/addItemAppraisal.htm",data:{itemId:itemId,itemGroupId:itemGroupId,comment:comment},success: function(data) { 
	        if (data.success) {
	        	$("#comment").val("");
	        	$("#comment").focus();
	            $("#itemAppraisal_container").gotoPage(1,$("#itemGroupId").val());
	        } else {
	        	jAlert("评论失败!","提示信息");
	        }
        }
    });
}

//评价的ajax分页
	$.extend($.fn,{
        // 加载 内容
        gotoPage:function(index,itemGroupId){
          var _this=this;
          var message = prepareErrorMessage("正在加载...","<img src='common/images/loading.gif'/>");
		  $(_this).html(message);
          $.ajaxSetup({
        	  <strong><span style="color:#ff0000;">cache:false,</span></strong>
        	  timeout: 30000,//30秒超时时间
        	  error: function (xhr,status,e){
	    		  if(status=="timeout"){
	    			  var message = prepareErrorMessage("页面链接超时,请重新刷新","<a href='javascript:void(0)' onclick='window.location.reload();'>刷新</a>");
	        		  $(_this).html(message);
	    		  }
        	  }
          });
          $.get(shop_Path+"front/getItemAppraisal.htm",{page:index,itemGroupId:itemGroupId},function($html){
        	if($html.msg){
        		var message = prepareErrorMessage($html.msg,"");
        		$(_this).html(message);
        		return false;
        	}
        	$(_this).html($html);
          });
        }
    });

以上代码在没有加入红色部分之前,在IE8、10,firefox,google等浏览器都是okey的,但是唯独在IE9下不行,把IE9关了,又重新打开,就能看到之前新增的记录,这时我们公司的前端大牛,过来看了一眼,缓存问题,然后加入了上面的那段,就可以了。


问题认证:因为IE9是


,设置为“自动”时,IE不会自动清除浏览器缓存,但是像IE8、10等其他浏览器为“每次访问网页时(E)”,就是每次请求都检测最新的,所以就不会有缓存问题。

原文地址:https://www.jb51.cc/ajax/164703.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐