angularjs怎么清除在ie下的缓存
这是我自己从网上找来的代码,自己也在用(兼容ie8+)。以下代码放在config 中即可,主要是用于防止ie 浏览器缓存 get 请求,希望能帮到你。
// Initialize get if not there
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
// Enables Request.IsAjaxRequest() in ASP.NET MVC
$httpProvider.defaults.headers.common['X-Requested-With'] =
'XMLHttpRequest';
// Disable IE ajax request caching
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
$httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
在你的路由文件的后面加上这句话就可以了
// 一般是angular.module('xxx').config(...)
// 禁止模板缓存
angular.module('xxx').run(['$rootScope', '$templateCache', function($rootScope, $templateCache) {
$rootScope.$on('$routeChangeStart', function(event, next, current) {
if (typeof(current) !== 'undefined'){
$templateCache.remove(current.templateUrl);
}
});
}]);
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
ctrl+f5强制清除缓存刷新