Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery成功后刷新/重新加载页面_Jquery_Wordpress_Switchers - Fatal编程技术网

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

jQuery成功后刷新/重新加载页面,jquery,wordpress,switchers,Jquery,Wordpress,Switchers,在我的主题顶部有一个样式切换条。它在大多数情况下都能工作,但您必须按F5或刷新才能看到新样式。如何完成jQuery,以便在成功执行后自动刷新 jQuery.fn.styleSwitcher = function(){ $(this).click(function(){ loadStyleSheet(this); return false; }); function loadStyleSheet(obj) { $('b

在我的主题顶部有一个样式切换条。它在大多数情况下都能工作,但您必须按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.fn.styleSwitcher=function(){
$(此)。单击(函数(){
加载样式表(本);
返回false;
});
函数加载样式表(obj){
$('body')。追加('');
$('body').css({height:'100%});
$(“#叠加”)
.css({
显示:“无”,
位置:'绝对',
排名:0,
左:0,,
宽度:“100%”,
高度:“100%”,
zIndex:1000,
背景:“黑色url”(http://mytheme.com/loading.gif)无重复中心'
})
.fadeIn(500,函数(){
$.get(obj.href+'&js',函数(数据){
$(“#样式表”).attr('href','css/'+data+'.css');
cssDummy.check(函数(){
$('#overlay').fadeOut(500,function(){
$(this.remove();
}); 
});
});
});
}
var cssDummy={
init:function(){
$('')。附于('正文');
},
检查:函数(回调){
if($('#伪元素').width()==2)callback();
else setTimeout(函数(){cssDummy.check(回调)},200);
}
}
cssDummy.init();
}
$.ajax({
成功:函数(){
$('#overlay')。加载('http://mytheme.com');
}
});

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

您可以使用

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

你可以使用它,这可能会对你有所帮助

我从你那里得到这个密码

您可以使用:

document.location.reload();

只需将此代码放在
$中。get()
块可能就在更新
#stylesheet
元素的行上方。
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();