加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

禁用AngularJS $http缓存

发布时间:2020-12-17 07:57:30 所属栏目:安全 来源:网络整理
导读:我正在尝试在我的AngularJS应用程序中禁用缓存,但它不能使用以下代码: $http.get("myurl",{cache:false}) 当我使用“myurl random =”Math.random()时,缓存被禁用;但是,我想要一个不同的方法. 这已经回答了 here. 粘贴链接中的代码段以供参考. myModule.con
我正在尝试在我的AngularJS应用程序中禁用缓存,但它不能使用以下代码:
$http.get("myurl",{cache:false})

当我使用“myurl& random =”Math.random()时,缓存被禁用;但是,我想要一个不同的方法.

这已经回答了 here.

粘贴链接中的代码段以供参考.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读