$http 的 Angular IE 缓存问题 [英] Angular IE Caching issue for $http

查看:18
本文介绍了$http 的 Angular IE 缓存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 IE 发送的所有 ajax 调用都由 Angular 缓存,并且我收到所有后续调用的 304 响应.尽管请求是相同的,但在我的情况下,响应不会相同.我想禁用这个缓存.我尝试将 cache 属性 添加到 $http.get 但仍然没有帮助.如何解决这个问题?

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. 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. How can this issue be resolved?

推荐答案

我没有为每个 GET 请求禁用缓存,而是在 $httpProvider 中全局禁用它:

Instead of disabling caching for each single GET-request, I disable it globally in the $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';
}]);

这篇关于$http 的 Angular IE 缓存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆