Javascript重定向页面和刷新缓存在同一时间


javascript redirect page and refresh cache at the same time

我有一个问题,当我重定向用户编辑配置文件后,他编辑配置文件图片。我重定向他到他的用户页面,但它不显示编辑的图片,只有当他手动刷新页面。以下是重定向到profile .php的profile_edit.php页面的代码:

<script type="text/javascript">
$(document).ready(function() {
    var f = $(''form'');
    var b = $(''#submit1''); // upload button

    b.click(function(){
        // implement with ajaxForm Plugin
        f.ajaxForm({
            beforeSend: function(){
            },
            success: function(e){
                window.location=''profil.php?user='.$user_session.''';
            },
            error: function(e){
            }
        });
    });
});
</script>   

在url中再添加一个参数用于缓存破坏

window.location=''profil.php?pram='+Math.random()+'&user='.$user_session.''';

首先-您可以添加一些散列,以首选缓存,如

window.location=''profil.php?user='.$user_session.'&rand='.mt_rand().''';

这将创建新的url -因此浏览器将加载新的页面

这是可能的,你需要添加这个技巧到图像url -请检查这个时刻

如果你需要刷新页面(你的当前url等于新的url) -使用

window.location.reload(true);

在成功回调,而不是重定向- true说浏览器刷新页面