有在我的主题顶部的风格切换栏。它的工作原理在大多数情况下,但你必须按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');
  }
 });
有帮助吗?

解决方案

可以使用

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

其他提示

window.location.reload(true); 

将达到目的。

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

您可以使用这可能帮助你。

我得到从这个代码刷新页面

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); 
   }
}

可以使用:

document.location.reload();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top