本文介绍了禁用AngularJS $ http缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试禁用AngularJS应用程序中的缓存,但不适用于以下代码:
I'm trying to disable the cache in my AngularJS app, but it isn't working with the following code:
$http.get("myurl",{cache:false})
当我使用"myurl&random="+Math.random()
时,缓存被禁用;但是,我想要一种不同的方法.
When I use "myurl&random="+Math.random()
, the cache is disabled; but, I'd like a different approach.
推荐答案
此问题已得到这里.
粘贴链接中的代码段供您参考.
Pasting code snippet from the link for your reference.
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';
}]);
这篇关于禁用AngularJS $ http缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!