0

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.

Vijay
  • 1
  • 3
  • possible duplicate of [How to prevent a jQuery Ajax request from caching in Internet Explorer?](http://stackoverflow.com/questions/4303829/how-to-prevent-a-jquery-ajax-request-from-caching-in-internet-explorer) –  Oct 27 '14 at 17:40
  • @E.Maggini I have tried the methods listed there but with no luck. – Vijay Oct 27 '14 at 18:06

2 Answers2

0
       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.

Vijay
  • 1
  • 3
-1

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.

Community
  • 1
  • 1
Apul Gupta
  • 3,044
  • 3
  • 22
  • 30