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

问题描述 投票:0回答:2

我正在向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
2个回答
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

0
投票

this help me

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

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

© www.soinside.com 2019 - 2024. All rights reserved.