【问题标题】:jQuery Refresh/Reload Page After Success成功后 jQuery 刷新/重新加载页面
【发布时间】:2009-12-14 17:18:51
【问题描述】:

在我的主题顶部有一个样式切换栏。它在大多数情况下都有效,但您必须按 F5 或刷新才能看到新样式。如何在成功执行后完成此 jQuery 以自动刷新?

    jQuery.fn.styleSwitcher = function(){
    $(this).click(function(){
        loadStyleSheet(this);
        return false;
    });
    function loadStyleSheet(obj) {
        $('body').append('<div id="overlay" />');
        $('body').css({height:'100%'});
        $('#overlay')
            .css({
                display: 'none',
                position: 'absolute',
                top:0,
                left: 0,
                width: '100%',
                height: '100%',
                zIndex: 1000,
                background: 'black url(http://mytheme.com/loading.gif) no-repeat center'
            })
            .fadeIn(500,function(){
                $.get( obj.href+'&js',function(data){
                    $('#stylesheet').attr('href','css/' + data + '.css');
                    cssDummy.check(function(){
                        $('#overlay').fadeOut(500,function(){
                            $(this).remove();
                        }); 
                    });
                });
            });
    }
    var cssDummy = {
        init: function(){
            $('<div id="dummy-element" style="display:none" />').appendTo('body');
        },
        check: function(callback) {
            if ($('#dummy-element').width()==2) callback();
            else setTimeout(function(){cssDummy.check(callback)}, 200);
        }
    }
    cssDummy.init();
}
$.ajax({
  success:function(){
       $('#overlay').load('http://mytheme.com');
  }
 });

【问题讨论】:

    标签: jquery wordpress switchers


    【解决方案1】:

    你可以使用

    success: function() {
        window.location.reload(true);
    }
    

    【讨论】:

      【解决方案2】:
      window.location.reload(true); 
      

      会成功的。

      【讨论】:

      • 只需将此代码放在$.get() 块中,可能就在您更新#stylesheet 元素的行上方。
      【解决方案3】:

      window.location = window.location.pathname 将执行刷新。

      【讨论】:

        【解决方案4】:

        你可以使用:

        document.location.reload();
        

        【讨论】:

          【解决方案5】:

          你可以使用它可能会帮助你

          我从to refresh page得到这个代码

          success: function(data){
             if(data.success == true){ // if true (1)
                setTimeout(function(){// wait for 5 secs(2)
                     location.reload(); // then reload the page.(3)
                }, 5000); 
             }
          }
          

          【讨论】:

            猜你喜欢
            • 2018-05-09
            • 2017-02-27
            • 2012-02-08
            • 2021-11-19
            • 2011-12-14
            • 2015-02-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多