成功后jQuery刷新/重新加载页面

时间:2009-12-14 17:18:52

标签: jquery wordpress switchers

在我的主题顶部有一个样式切换栏。它在很大程度上起作用,但你必须按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');
  }
 });

5 个答案:

答案 0 :(得分:59)

您可以使用

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

答案 1 :(得分:7)

window.location.reload(true); 

会做到这一点。

答案 2 :(得分:0)

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

答案 3 :(得分:0)

你可以用这个可以帮到你

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

答案 4 :(得分:0)

你可以使用:

document.location.reload();
相关问题