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

高洛峰
Release: 2017-01-14 11:52:00
Original
1239 people have browsed it

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template