小编典典

$ http的Angular IE Caching问题

javascript

从IE发送的所有ajax调用均由Angular缓存,我304 response为所有后续调用获取了a
。尽管请求是相同的,但在我的情况下响应不会是相同的。我想禁用此缓存。我尝试将其添加cache attribute到$
http.get中,但仍然无济于事。该问题如何解决?


阅读 270

收藏
2020-04-25

共1个答案

小编典典

我没有为每个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';
}]);
2020-04-25