Home >Web Front-end >JS Tutorial >AngularJS is always a solution to the caching problem when fetching data under IE

AngularJS is always a solution to the caching problem when fetching data under IE

高洛峰
高洛峰Original
2017-01-14 11:52:001245browse

The example in this article describes how to solve the problem of AngularJS always caching data when fetching it under IE. Share it with everyone for your reference, the details are as follows:

question:

When using AngularJS to make a request (GET) to obtain server-side data, and then bind it to the page, you will find that the original data result is always displayed in IE. At this time we will know that IE has cached.

Solution:

We can set it not to cache through $httpProvider in the AngularJS configuration. The details are as follows:

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';
});

I hope this article will be helpful to everyone in AngularJS programming.

For more related articles on how to solve the caching problem when fetching data under IE with AngularJS, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Cache usage in AngularJSNext article:Cache usage in AngularJS