问题:

在使用AngularJS发出请求(GET)获取服务端数据,然后再绑定到页面中,你会发现在IE中总是显示原来的数据结果。这时候我们就会知道,IE做了缓存。

解决办法:

我们可以在AngularJS的配置中通过$httpProvider来设置其不缓存。具体如下所示:

ngApp.config(function ($httpProvider) {
  // 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';
  //禁用IE对ajax的缓存
  $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
  $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
});
 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
猜你喜欢
  • 2021-12-01
  • 2021-12-25
  • 2021-08-06
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案