我有以下javascript代码,显示确认框并更新客户表。它用于存档客户。但点击取消时,JS Alert框有时不会消失?在调用方法之前是否需要等待?可能导致问题的原因是什么?感谢
$(function(){
$("#archiveme").click(function(){
var data = { 'cust[]' : []};
$(":checked").each(function() {
data['cust[]'].push($(this).val());
});
var askthem = confirm("Are you sure want to archive these contacts?");
if(askthem)
{
$.ajax({
type: "POST",
url: "ajax/customers-process.php?action=archive",
data: data,
cache: false,
success: function (html) {
updateCustomers(customers, corder)
}
});
}
else
{
updateCustomers(customers, corder)
}
return false;
});
});
评论中提到的整个代码。
function updateCustomers(ct, co) {
$("#customer-area").hide(200);
if (ct == "all") {
var customers = "all";
$("#all-but").addClass("active");
$("#arc-but").removeClass("active");
$("#page-title").html('All Customers').fadeIn();
}
else if (ct == "arc") {
var customers = "arc";
$("#arc-but").addClass("active");
$("#all-but").removeClass("active");
$("#page-title").html('Archived Customers').fadeIn();
}
var corder = co;
var datac = 'type=' + ct + '&order=' + co;
$("#customer-area").html('<div id="loader"><img src="img/loader.gif"></div>');
$.ajax({
type: "GET",
url: "ajax/customers.php",
data: datac,
cache: false,
success: function (html) {
$("#customer-area").ajaxComplete(function (event, request) {
$("#customer-area").html(html).fadeIn(300);
$(function () {
$(".cust-order").click(function () {
var corder = $(this).attr("id");
updateCustomers(customers, corder);
});
$(function () {
$("#archiveme").click(function () {
var data = { 'cust[]': [] };
$(":checked").each(function () {
data['cust[]'].push($(this).val());
});
var askthem = confirm("Are you sure want to archive these contacts?");
if (askthem) {
$.ajax({
type: "POST",
url: "ajax/customers-process.php?action=archive",
data: data,
cache: false,
success: function (html) {
updateCustomers(customers, corder)
}
});
}
else {
//close()
}
return false;
})
})
});
});
}
});
}