【问题标题】:IE 11 issue - automatically cache responses from GET requests - ReactjsIE 11 问题 - 自动缓存来自 GET 请求的响应 - Reactjs
【发布时间】:2019-07-01 05:37:23
【问题描述】:

我正在向 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(() => {
           });
  }
}

任何帮助将不胜感激。

【问题讨论】:

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


    【解决方案1】:

    尝试参考this thread在url中添加时间戳,或者参考this article添加Cache-Control: no-cache header set。

    这样的代码:

    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
    

    【讨论】:

      【解决方案2】:

      this help me

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

      axios.defaults.headers.get['Cache-Control'] = 'no-cache, no-store';

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多