Fetching data from AngularJS under IE is always the solution to cache problem

  • 2021-07-09 06:49:15
  • OfStack

This article example tells the AngularJS in IE data always cache solution. Share it for your reference, as follows:

Question:

When you use AngularJS to make a request (GET) to get server data and then bind it to the page, you will find that the original data results are always displayed in IE. At this time, we will know that IE is cached.

Solution:

We can set it not to cache with $httpProvider in the configuration of AngularJS. 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';
  // Disable IE Right ajax Cache of 
  $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
  $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
});

I hope this article is helpful to everyone's AngularJS programming.


Related articles: