Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

All the ajax calls that are sent from the IE are cached by Angular and I get a 304 response for all the subsequent calls.(从IE发送的所有ajax调用都被Angular缓存,我为所有后续调用获得304 response 。)

Although the request is the same, the response is not going be the same in my case.(尽管请求是相同的,但在我的情况下响应不会是相同的。) I want to disable this cache.(我想禁用此缓存。) I tried adding the cache attribute to $http.get but still it didn't help.(我尝试将cache attribute添加到$ http.get,但仍然没有帮助。) How can this issue be resolved?(该问题如何解决?)   ask by Rahul translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
247 views
Welcome To Ask or Share your Answers For Others

1 Answer

Instead of disabling caching for each single GET-request, I disable it globally in the $httpProvider:(我没有为每个GET请求禁用缓存,而是在$ httpProvider中全局禁用了它:)

myModule.config(['$httpProvider', function($httpProvider) {
    //initialize get if not there
    if (!$httpProvider.defaults.headers.get) {
        $httpProvider.defaults.headers.get = {};    
    }    

    // Answer edited to include suggestions from comments
    // because previous version of code introduced browser-related errors

    //disable IE ajax request caching
    $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT';
    // extra
    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...