如何解决angularJS route 缓存问题 如题。angularjs加载不同的路由模板,但是它总是使用缓存,重新加载页面都没用。这样岂不是都取不到数据库的最新数据。如何才能禁止路由机制使用缓存?比如:我首次进入修改界面,修改完数据保存,然后返回在进入编辑页面 ,页面内容是修改之前的内容,但是数据库中这些数据已经被更改过了!angularJS 总是会读取route缓存中的内容,而不是去读取数据库了,这种解决掉这种缓存 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var app = angular.module('phonecat', ['ngRoute']);app.config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) { if (!$httpProvider.defaults.headers.get) { $httpProvider.defaults.headers.get = {}; } $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest'; $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; $routeProvider. when('/phones', { templateUrl: 'phone-list.html', controller: PhoneListCtrl }). when('/phones/:phoneId', { templateUrl: 'phone-detail.html', controller: PhoneDetailCtrl }). otherwise({ redirectTo: '/phones' }); }]); .factory('myInterceptor', function ($q) { var interceptor = { 'request': function (config) { // 成功的请求方法 var ts = '?^=' + new Date().getTime(); if (config.url.indexOf('?') > 0) config.url = config.url.replace('?', ts + '&'); else config.url = config.url + ts; return config; // 或者 $q.when(config); }, 'response': function (response) { // 响应成功 return response; // 或者 $q.when(config); }, 'requestError': function (rejection) { // 请求发生了错误,如果能从错误中恢复,可以返回一个新的请求或promise return response; // 或新的promise // 或者,可以通过返回一个rejection来阻止下一步 // return $q.reject(rejection); }, 'responseError': function (rejection) { // 请求发生了错误,如果能从错误中恢复,可以返回一个新的响应或promise return rejection; // 或新的promise // 或者,可以通过返回一个rejection来阻止下一步 // return $q.reject(rejection); } }; return interceptor; }) .config(['$httpProvider', function ($httpProvider) { $httpProvider.interceptors.push('myInterceptor'); }])Powered By:http://www.jinwmmail.xyz:8080/ 请求数据是不是用$http.get了,第二个参数那里,加个cache:false试试 二楼的方法,连html模板都缓存不了了 js中{}的使用 急~~将jsp 内容导出到world jquery div 下checkbox 关于jquery获取URL参数的问题 如何把一个iframe中的页面显示在另外一个iframe中? ExtJS 中的树 如何让某个节点 默认是选中状态 如何检测字符串里有"\n",请高手进! DOM中关于LoadXML的问题 怎样用JavaScript提交Form,提交前设置好值? 500分求菜单功能。 请教Javascript如何实现双击选中页面中英文单词并将其颜色改变的功能 jstree 展开状态问题
app.config(['$routeProvider', '$httpProvider',
function($routeProvider, $httpProvider) {
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
$httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; $routeProvider.
when('/phones', {
templateUrl: 'phone-list.html',
controller: PhoneListCtrl
}).
when('/phones/:phoneId', {
templateUrl: 'phone-detail.html',
controller: PhoneDetailCtrl
}).
otherwise({
redirectTo: '/phones'
});
}
]);
var interceptor = {
'request': function (config) {
// 成功的请求方法
var ts = '?^=' + new Date().getTime();
if (config.url.indexOf('?') > 0)
config.url = config.url.replace('?', ts + '&');
else
config.url = config.url + ts;
return config; // 或者 $q.when(config);
},
'response': function (response) {
// 响应成功
return response; // 或者 $q.when(config);
},
'requestError': function (rejection) {
// 请求发生了错误,如果能从错误中恢复,可以返回一个新的请求或promise
return response; // 或新的promise
// 或者,可以通过返回一个rejection来阻止下一步
// return $q.reject(rejection);
},
'responseError': function (rejection) {
// 请求发生了错误,如果能从错误中恢复,可以返回一个新的响应或promise
return rejection; // 或新的promise
// 或者,可以通过返回一个rejection来阻止下一步
// return $q.reject(rejection);
}
};
return interceptor;
})
.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('myInterceptor');
}])Powered By:http://www.jinwmmail.xyz:8080/