Home  >  Article  >  Web Front-end  >  Solution to the problem of data caching in Angularjs in 360 compatibility mode

Solution to the problem of data caching in Angularjs in 360 compatibility mode

PHP中文网
PHP中文网Original
2017-06-22 14:31:061470browse

The example in this article describes how to solve the problem of AngularJS always caching when fetching data 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 the server data, and then bind it to the page, you will find that in IE The original data results are always displayed in . 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';
});

The above is the detailed content of Solution to the problem of data caching in Angularjs in 360 compatibility mode. For more information, please follow other related articles on 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