jQuery 成功后jQuery刷新/重新加载页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1902233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Refresh/Reload Page After Success
提问by Greg
have a style switcher bar across the top of my theme. It works for the most part, but you have to hit F5 or Refresh to see the new style. How do I finish this jQuery to auto-refresh upon a successful execution?
在我的主题顶部有一个样式切换器栏。它在大多数情况下都有效,但您必须按 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');
}
});
回答by Mickel
You can use
您可以使用
success: function() {
window.location.reload(true);
}
回答by Wookai
window.location.reload(true);
will do the trick.
会做的伎俩。
回答by Jordan Ryan Moore
window.location = window.location.pathname
will perform a refresh.
window.location = window.location.pathname
将执行刷新。
回答by Jonathan Burgos Gio
you can use:
您可以使用:
document.location.reload();
回答by naveen kumar
you can use this might help you
你可以用这可能对你有帮助
i got this code from 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);
}
}