jQuery Actualizar / Recargar página después del éxito
Pregunta
tener una barra de conmutador de estilo en la parte superior de mi tema. Se trabaja en su mayor parte, pero usted tiene que golpear F5 o Actualizar para ver el nuevo estilo. ¿Cómo puedo terminar este jQuery para la actualización automática en una ejecución exitosa?
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');
}
});
Solución
Puede utilizar
success: function() {
window.location.reload(true);
}
Otros consejos
window.location.reload(true);
hará el truco.
window.location = window.location.pathname
llevará a cabo una actualización.
puede utilizar esto podría ayudarle a
me dieron el código de para actualizar la página
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);
}
}
puede utilizar:
document.location.reload();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow