Avi*_*ash 3 internet-explorer caching cross-browser angularjs
我的技术堆栈是 -
我在做什么 :
有一个项目列表,我正在做CRUD(创建,读取,更新和删除)
我的目标是在没有页面重新加载的情况下实现实时数据操作.
这在Chrome中运行良好.但是,IE无法检测到模型更改.它在添加/更新/删除(从其缓存)之前继续显示数据.只有在我手动清除缓存后,我才能看到更改后的模型.
需要有关如何使用IE8及更高版本解决此问题的帮助.
PS我已经尝试过设置元标题
你可以设置
"无缓存标头到服务器端的响应"
var AppInfrastructure = angular.module('App.Infrastructure', []);
Run Code Online (Sandbox Code Playgroud)
在Angularjs中你可以编写拦截器,下面是示例代码:
AppInfrastructure
.config(function ($httpProvider) {
$httpProvider.requestInterceptors.push('httpRequestInterceptorCacheBuster');
})
.factory('httpRequestInterceptorCacheBuster', function () {
return function (promise) {
return promise.then(function (request) {
if (request.method === 'GET') {
var sep = request.url.indexOf('?') === -1 ? '?' : '&';
request.url = request.url + sep + 'cacheSlayer=' + new Date().getTime();
}
return request;
});
};
});
Run Code Online (Sandbox Code Playgroud)
与上面提到的Jquery Guru相同,但它是更新版本的角度配置
.factory('noCacheInterceptor', function () {
return {
request: function (config) {
console.log(config.method);
console.log(config.url);
if(config.method=='GET'){
var separator = config.url.indexOf('?') === -1 ? '?' : '&';
config.url = config.url+separator+'noCache=' + new Date().getTime();
}
console.log(config.method);
console.log(config.url);
return config;
}
};
});
Run Code Online (Sandbox Code Playgroud)
你应该在验证后删除console.logs
| 归档时间: |
|
| 查看次数: |
4193 次 |
| 最近记录: |