从 IE 发送的所有 ajax 调用都由 Angular 缓存,我得到304 response所有后续调用的一个。尽管请求是相同的,但在我的情况下响应不会相同。我想禁用这个缓存。我尝试将其添加cache attribute到 $http.get 但仍然没有帮助。如何解决这个问题?
304 response
cache attribute
我没有为每个 GET 请求禁用缓存,而是在 $httpProvider 中全局禁用它:
myModule.config(['$httpProvider', function($httpProvider) { //initialize get if not there if (!$httpProvider.defaults.headers.get) { $httpProvider.defaults.headers.get = {}; } // Answer edited to include suggestions from comments // because previous version of code introduced browser-related errors //disable IE ajax request caching $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; // extra $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; }]);