我有一个页面上有很多复选框,我写了一个 JS 代码来为每个页面调用 PHP 页面,我想在调用完成后刷新页面。 这是我的代码
$(".matchFrnds").each(function(){ //For each CheckBox
if($(this).is(':checked')){
var sendData= $(this).val();
$.post('Call to PHP Page',{sendData:sendData},function(data){
window.location.reload();
});
}
});
问题是页面会在完成几个复选框后重新加载,所以如果有 60 个复选框,页面会在调用 10 个复选框后重新加载。我还更改了 window.location.reload();
的位置,但结果是一样的,我希望在所有复选框的调用完成后重新加载。
最佳答案
您可以查看您完成了多少次调用然后重新加载
var boxes = $(".matchFrnds:checked").length;
var calls = 0;
$(".matchFrnds").each(function(){ //For each CheckBox
if($(this).is(':checked')){
var sendData= $(this).val();
$.post('Call to PHP Page',{sendData:sendData},function(data){
calls++;
if(calls >= boxes) {
window.location.reload();
}
});
}
});
关于javascript - 请求完成后页面刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20238620/