2009-12-14 50 views
13

có thanh trình chuyển đổi kiểu ở phía trên cùng của chủ đề của tôi. Nó hoạt động cho hầu hết các phần, nhưng bạn phải nhấn F5 hoặc Refresh để xem phong cách mới. Làm cách nào để hoàn thành jQuery này để tự động làm mới sau khi thực hiện thành công?Làm mới jQuery/Tải lại trang sau khi thành công

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'); 
    } 
}); 

Trả lời

59

Bạn có thể sử dụng

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

window.location = window.location.pathname sẽ thực hiện làm mới.

7
window.location.reload(true); 

sẽ làm các trick.

+0

nào để tôi đặt đó ở đâu? – Greg

+0

Mickel đã nhận nó;)! – Wookai

+0

chỉ cần đặt mã này bên trong khối '$ .get()', có thể nằm ngay trên dòng nơi bạn cập nhật phần tử '# stylesheet'. – Firnas

0

bạn có thể sử dụng điều này có thể giúp bạn

tôi đã nhận mã này từ 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); 
    } 
} 
0

bạn có thể sử dụng:

document.location.reload(); 
Các vấn đề liên quan