我正在尝试在我的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'; }]);