如何使用AngularJS模型时美元IE8 p $ pvent缓存 [英] How to Prevent Caching in IE8 when using AngularJS Models
问题描述
我的技术堆栈 -
- AngularJS
- 引导
- Spring MVC的
- 休眠
我在做什么:
有哪些我做的CRUD(创建,读取,更新和删除)
产品列表- 发布通过角控制器表单数据到一个Spring控制器。
- 春季控制器 - > DAO方法 - > DB更新
- 弹簧控制器返回Y或N
- 角得到状态消息和重新加载角模型(JSON数组来填充的项目列表)
- 用同样的更新和删除
我的目标是实现实时数据,而无需重新加载页面。
这在Chrome中工作正常。
但是,IE浏览器无法检测更改模型。它使前加/选择更新/删除显示数据(从缓存)。
只有当我手动清除缓存,是我居然能看到改变的模型。
需要有关如何与IE8解决这一问题及以上的帮助。
P.S。我已经尝试设置元标题
您可以设置
无缓存标头在服务器端的响应
块引用>VAR AppInfrastructure = angular.module('App.Infrastructure',[]);
和在Angularjs你可以写下面拦截器样品code:
AppInfrastructure
的.config(函数($ httpProvider){
$ httpProvider.requestInterceptors.push('HTT prequestInterceptorCacheBuster');
})
.factory('HTT prequestInterceptorCacheBuster',函数(){
复位功能(承诺){
返回promise.then(功能(要求){
如果(request.method ==='GET'){
VAR月= request.url.indexOf('?')=== -1? ? :'和;';
request.url = request.url +月+'cacheSlayer ='+新的Date()的getTime()。
} 返回请求;
});
};
});My technology stack is -
- AngularJS
- Bootstrap
- Spring MVC
- Hibernate
What am I doing :
There is a list of Items on which I am doing CRUD (Create, Read, Update and Delete)
- Posting form Data via Angular Controller to a Spring Controller.
- Spring Controller -> DAO method -> DB is updated
- Spring Controller Returns "Y" or "N"
- Angular gets the Status Message and Reloads the Angular Model(A Json Array to populate the List of Items)
- Same with Update and Delete
My objective is to achieve real-time data manipulation without page reload.
This works fine in Chrome. However, IE can not detect the Model Change. It keeps displaying the data prior to addition/updation/deletion (from its cache). Only after I clear the cache manually, am I actually able to see the changed Model.
Need help on how to resolve this problem with IE8 and above.
P.S. I have already tried setting the meta headers
解决方案You can set
"No-Cache headers to the response on server side"
var AppInfrastructure = angular.module('App.Infrastructure', []);
and in Angularjs you can write interceptor below is the sample code:
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; }); }; });
这篇关于如何使用AngularJS模型时美元IE8 p $ pvent缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!