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

前端之家收集整理的这篇文章主要介绍了神奇的IE9,Ajax请求缓存问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

相关的代码如下:

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

  1. //新增评价
  2. function addItemAppraisal(itemId,itemGroupId){
  3. var comment = $("#comment").val();
  4. $.ajax({
  5. url: shop_Path+"front/addItemAppraisal.htm",data:{itemId:itemId,itemGroupId:itemGroupId,comment:comment},success: function(data) {
  6. if (data.success) {
  7. $("#comment").val("");
  8. $("#comment").focus();
  9. $("#itemAppraisal_container").gotoPage(1,$("#itemGroupId").val());
  10. } else {
  11. jAlert("评论失败!","提示信息");
  12. }
  13. }
  14. });
  15. }

  1. //评价的ajax分页
  2. $.extend($.fn,{
  3. // 加载 内容
  4. gotoPage:function(index,itemGroupId){
  5. var _this=this;
  6. var message = prepareErrorMessage("正在加载...","<img src='common/images/loading.gif'/>");
  7. $(_this).html(message);
  8. $.ajaxSetup({
  9. <strong><span style="color:#ff0000;">cache:false,</span></strong>
  10. timeout: 30000,//30秒超时时间
  11. error: function (xhr,status,e){
  12. if(status=="timeout"){
  13. var message = prepareErrorMessage("页面链接超时,请重新刷新","<a href='javascript:void(0)' onclick='window.location.reload();'>刷新</a>");
  14. $(_this).html(message);
  15. }
  16. }
  17. });
  18. $.get(shop_Path+"front/getItemAppraisal.htm",{page:index,itemGroupId:itemGroupId},function($html){
  19. if($html.msg){
  20. var message = prepareErrorMessage($html.msg,"");
  21. $(_this).html(message);
  22. return false;
  23. }
  24. $(_this).html($html);
  25. });
  26. }
  27. });

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


问题认证:因为IE9是


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

猜你在找的Ajax相关文章