2014-07-01 43 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(); 
    }); 
});