Home > Article > Web Front-end > Solution to the problem of data caching in Angularjs in 360 compatibility mode
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!