简体   繁体   English

尽管没有缓存标头,但最新的 Chrome 缓存 ajax 响应

[英]Latest Chrome caching ajax response despite no cache headers

I have a simple form in a modal that gets populated by a ajax request (to a server running Django)我在模态中有一个简单的表单,它由 ajax 请求填充(到运行 Django 的服务器)

If I add choices to a choice field, those choices are not displaying for a few minutes on the modal.如果我将选择添加到选择字段,这些选择不会在模态上显示几分钟。 This issues only appeared after updating to the latest version of chrome (80.3987.149).此问题仅在更新到最新版本的 chrome (80.3987.149) 后出现。

I am including no-cache headers in the ajax response like this:我在 ajax 响应中包含无缓存标头,如下所示:

    response['Cache-Control'] = 'no-cache, no-store, must-revalidate'
    response['Pragma'] = 'no-cache'
    response['Expires'] = '0'

But it doesn't seem to matter.但这似乎无关紧要。

My ajax call method looks like this:我的 ajax 调用方法如下所示:

openAlertModalOnclick(e) {
    e.preventDefault();
    let self = this;
    $.get($(e.target).attr("href"), resp => {
        $("#alertModal").html(resp.html).foundation("open").foundation();
        })
    }).fail(() => {
        this.showErrorToast("Error occurred while loading alerts.")
    })
}

I am 90% sure this is an issue with just the latest version of chrome, as I could not reproduce it until I updated chrome.我 90% 确定这只是最新版本的 chrome 的问题,因为在我更新 chrome 之前我无法重现它。 Is there anything else I can do to get chrome to stop caching the form?我还能做些什么来让 chrome 停止缓存表单?

The solution was the change the $.get call to $.ajax and pass in a cache: false parameter.解决方案是将 $.get 调用更改为 $.ajax 并传入 cache: false 参数。

The function to open the modal now looks like this:打开模态的函数现在看起来像这样:

    openForm52AlertModalOnclick(e) {
    e.preventDefault();
    let self = this;

    SpinnerController.showSpinner();

    $.ajax({
        url: $(e.target).attr("href"),
        method: 'GET',
        cache: false,
        success: function (resp) {
            $("#alertModal").html(resp.html).foundation("open").foundation();
        },
        error: function () {
            this.showErrorToast("Error occurred while loading alerts.")
        },

    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM