首页 > 解决方案 > 刷新页面时如何自动清除缓存?

问题描述

我正在使用 php + jquery 构建一个网站。

在一个jquery ajax页面中,每次ctrl+F5都要清缓存,否则这个页面的按钮不能点击。

我的想法是通过“window.location.reload(true);”强制刷新此页面 ,但我无法同时清除缓存!</p>

单击按钮而不是ctrl + F5后是否有任何Jquery或其他东西可以自动清除缓存?

我的代码如下:

...
$("[id = One_Click_Accept]").click(function(){

...

    $.ajax({
        url: WebsitePath + '/accreditation_check/' + CurAccreditationId,

        data: {
            accreditation_id: CurAccreditationId,
            IsAccredited: 1,
            CheckerName:$('#CheckerName').val(),
            CheckTime: Math.round(new Date().getTime()/1000).toString(), //it need a 10 digit timestamp to save to the db.
            TheCountry : TheCountry,
            TheSchool: TheSchool,
            TheDegree: TheDegree,
            TheMajor: TheMajor,
            YearOfGraduation: YearOfGraduation
        },
             type: "POST",
             dataType: 'json',
             cache: false,
        success: function (Result) {

            if (Result.Status == 1) {

                alert('认证成功');

            } else {
                alert('认证失败');

                $("#One_Click_Accept").val('再次认证');
            }
        },
        error: function () {
            alert('认证失败');
            $("#One_Click_Accept").val('再次认证');

        }
    });
}
//window.location.reload(true);
});

标签: phpjqueryhtmlcss

解决方案


谢谢你们!我通过使用“setTimeout(function()”来延迟加载时间来解决它。不仅如此,我还必须使用不同的选择器,它看起来像“$(document).on('click',"[id = One_Click_Accept ]",函数(e)"。


推荐阅读