简体   繁体   中英

IE 8 caching ajax calls

I am trying to get some data using ajax GET method, it works great in all the browsers except IE. In IE it is caching the data the first time the call is made and caching it I need to prevent it. I tried the following methods in my code but still unable to resolve the issue

1) Setting caching = false globally in the code $.ajaxSetup({ cache: false });

2) putting this in the meta tags

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

3)Using POST instead of GET method

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

                },

4)Tried including this bit in my code but with no success

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

Please help me with this issue, it has been bugging me for the past 2 days. Thank you in advance.

       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});     
        }

Altough my code is angular based I used jQuery ajax for all the service calls but tried to implement angular and ajax calls depending on the browser and that has solved my issue. I know it may not be the right approach but the only solution which worked for me.

As suggested in this post, How to prevent a jQuery Ajax request from caching in Internet Explorer? If you are using cache: false option, calls shouldn't be cached. What I found different is async option.

So, Try after changing, async: false to async: true in your ajax call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM