IE 11问题-自动缓存来自GET请求的响应-React.js

时间:2019-02-07 06:40:28

标签: ajax internet-explorer browser-cache cache-control get-request

我正在向Web服务发出GET请求以进行AJAX调用。 Internet Explorer正在自动缓存来自GET请求的响应。

  • 我第一次尝试请求就可以了。
  • 数据修改后,我仍然看到旧结果。
  • 一切似乎在其他浏览器中都能正常工作。

这是代码

export function fetchReportSet () {
  return function(dispatch) {
       axios.get(`${ROOT_URL}/api/reports/`, {
         headers: {Pragma: 'no-cache'},
         headers: {Authorization:'Token '+ localStorage.getItem('token')}
       })
           .then(response => {
             dispatch({type: FETCH_REPORT , payload: response.data});
           })
           .catch(() => {
           });
  }
}

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

尝试参考this thread在URL中添加时间戳,或参考this article添加Cache-Control:无高速缓存头集。

这样的代码:

import axios from 'axios';
import { cacheAdapterEnhancer } from 'axios-extensions';

const http = axios.create({
    baseURL: '/',
    headers: { 'Cache-Control': 'no-cache' },
    // cache will be enabled by default
    adapter: cacheAdapterEnhancer(axios.defaults.adapter)
});

http.get('/users'); // make real http request

答案 1 :(得分:0)

this help me

axios.defaults.headers.get ['Pragma'] ='no-cache';

axios.defaults.headers.get ['Cache-Control'] ='无缓存,无存储';

相关问题