Question

une barre de sélecteur de style en haut de mon thème. Il fonctionne pour la plupart, mais vous devez appuyez sur F5 ou Actualiser pour voir le nouveau style. Comment puis-je terminer cette jQuery pour rafraîchissement automatique sur une exécution réussie?

    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');
  }
 });
Était-ce utile?

La solution

Vous pouvez utiliser

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

Autres conseils

window.location.reload(true); 

fera l'affaire.

window.location = window.location.pathname effectuera un rafraîchissement.

vous pouvez utiliser cela pourrait vous aider

Je suis arrivé ce code de pour réactualiser la 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); 
   }
}

vous pouvez utiliser:

document.location.reload();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top