【问题标题】:IE 8 caching ajax callsIE 8 缓存 ajax 调用
【发布时间】:2014-12-22 23:07:31
【问题描述】:

我正在尝试使用 ajax GET 方法获取一些数据,它适用于除 IE 之外的所有浏览器。 在 IE 中,它在第一次调用时缓存数据并缓存它我需要防止它。 我在代码中尝试了以下方法,但仍然无法解决问题

1) 在代码中全局设置caching = false $.ajaxSetup({ cache: false });

2) 将其放入元标记中

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

3)使用 POST 代替 GET 方法

          $.ajax({  
                cache: false,
                type: "POST",
                url: '/XYZURL/' + Id,
                dataType: "json",
                async: false,
                success: function(Response) {                                   
                    $scope.data = Response;

                },

4)尝试在我的代码中包含这个位,但没有成功

if(url.replace("?") != url)
   url = url+"&rand="+new Date().getTime();
else
   url = url+"?rand="+new Date().getTime();

请帮我解决这个问题,过去 2 天它一直困扰着我。 提前谢谢你。

【问题讨论】:

标签: javascript jquery ajax internet-explorer caching


【解决方案1】:
       var browser = window.navigator.userAgent;
       var msie = browser.indexOf ( "MSIE " );
       if(msie > 0){
        var remoteId = index.entity.id;
         var  ie_fix = new Date().getTime();
             $.ajax({  
                    cache: false,
                    type: "GET",
                    url: '/XYZURL/' + Id,

                    dataType: "json",
                    async: true,
                    success: function(Response) {                                   
                        $scope.data = Response;
                    },
                    error: function(jqXHR,errorThrown) {                                
                        alert("jqXHR");
                    }
                });  
        }else{
            $scope.data = datafactory.show({id: index.id});     
        }

虽然我的代码是基于角度的,但我对所有服务调用都使用了 jQuery ajax,但尝试根据浏览器实现 angular 和 ajax 调用,这解决了我的问题。我知道这可能不是正确的方法,而是唯一对我有用的解决方案。

【讨论】:

    【解决方案2】:

    正如本文所建议的,How to prevent a jQuery Ajax request from caching in Internet Explorer? 如果您使用cache: false 选项,则不应缓存调用。我发现不同的是async 选项。

    所以,在您的 ajax 调用中将 async: false 更改为 async: true 后尝试。

    【讨论】:

    • 那你那边出了点问题。如果是直播,分享网址。
    猜你喜欢
    • 2011-11-08
    • 2011-02-24
    • 1970-01-01
    • 2012-01-11
    • 2015-12-25
    • 1970-01-01
    • 2023-04-07
    • 2011-05-02
    • 1970-01-01
    相关资源
    最近更新 更多