我正在使用jQuery ajax从表格中删除客户。在提交表单之前,如何显示确认框?最好使用jQuery的对话框。
我以前看到过类似的问题,但没有一个能帮助我。
这是我的代码:
$.ajax({
type: "POST",
url: "delete/process.php",
data: "delcustomerid="+ delcustomerid,
success: refreshTable
});
我正在使用jQuery ajax从表格中删除客户。在提交表单之前,如何显示确认框?最好使用jQuery的对话框。
我以前看到过类似的问题,但没有一个能帮助我。
这是我的代码:
$.ajax({
type: "POST",
url: "delete/process.php",
data: "delcustomerid="+ delcustomerid,
success: refreshTable
});
ajax函数有一个beforeSend
事件,您可以使用它在提交表单之前显示对话框。
如果对话框指示不应提交表单,则您需要从函数中返回false,以便不会进行表单提交。
在您的情况下,您需要执行以下操作:
$.ajax({
beforeSend: function (request) {
// This is where you show the dialog.
// Return false if you don't want the form submitted.
},
type: "POST",
url: "delete/process.php",
data: "delcustomerid="+ delcustomerid,
success: refreshTable
});
ajax
相同的参数。请注意保留HTML标签。function DeleteWithCheck() {
if (confirm("Are you sure you want to delete customer "+delcustomerid.ToString()))
{
$.ajax({
type: "POST",
url: "delete/process.php",
data: "delcustomerid="+ delcustomerid,
success: refreshTable
});
}
else
alert("Aborted");
}
当您想要执行删除操作时,请调用此函数。