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!