如何使用AngularJS模型时美元IE8 p $ pvent缓存 [英] How to Prevent Caching in IE8 when using AngularJS Models

查看:127
本文介绍了如何使用AngularJS模型时美元IE8 p $ pvent缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的技术堆栈 -


  1. AngularJS

  2. 引导

  3. Spring MVC的

  4. 休眠

我在做什么:

有哪些我做的CRUD(创建,读取,更新和删除)

产品列表

  1. 发布通过角控制器表单数据到一个Spring控制器。

  2. 春季控制器 - > DAO方法 - > DB更新

  3. 弹簧控制器返回Y或N

  4. 角得到状态消息和重新加载角模型(JSON数组来填充的项目列表)

  5. 用同样的更新和删除

我的目标是实现实时数据,而无需重新加载页面。

这在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 -

  1. AngularJS
  2. Bootstrap
  3. Spring MVC
  4. Hibernate

What am I doing :

There is a list of Items on which I am doing CRUD (Create, Read, Update and Delete)

  1. Posting form Data via Angular Controller to a Spring Controller.
  2. Spring Controller -> DAO method -> DB is updated
  3. Spring Controller Returns "Y" or "N"
  4. Angular gets the Status Message and Reloads the Angular Model(A Json Array to populate the List of Items)
  5. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆