2014-07-01 39 views
-1
$('.active-per').click(function() { 
    var text = $(this).data('value'); 
    $('.active-per').removeClass('active'); 

    if (text == "t") { 
     $(this).addClass("active"); 
     $.post("percentage.php", { 
      'text': text 
     }, function (data) {}); 
    } 
    else if (text == "n") { 
     $(this).addClass("active"); 
     $.post("percentage.php", { 
      'text': text 
     }, function (data) {}); 
    } 
    else if (text == "c") { 
     $(this).addClass("active"); 
     $.post("percentage.php", { 
      'text': text 
     }, function (data) {}); 
    } 
    else if (text == "r") { 
     $(this).addClass("active"); 
     $.post("percentage.php", { 
      'text': text 
     }, function (data) {}); 
    } 

    window.location.reload(); 
}); 

我需要刷新我的網頁後,才POST請求已經done.But如果我做這樣的不happening.I可以得到的,更變量後我刷新後,已將如何在發送後數據後重新加載。刷新後的請求已經完成後才

回答

0

所有內部IF$.post方法 - ELSE條件,使1請求將進行後的時間,這樣你就可以在變量分配post功能狀態,並在代碼的最後檢查。 試試這個方法

$('.active-per').click(function() { 
    var text = $(this).data('value'); 
    $('.active-per').removeClass('active'); 

    var ajax = null; 

    if (text == "t") { 
     $(this).addClass("active"); 
     ajax = $.post("percentage.php", { 
      'text': text 
     }, function (data) {}); 
    } 
    . 
    . 
    . 
    else if (text == "r") { 
     $(this).addClass("active"); 
     ajax = $.post("percentage.php", { 
      'text': text 
     }, function (data) {}); 
    } 

    ajax.done(function(){ 
    window.location.reload(); 
    }); 
});