在发送 ajax 请求之前,我需要一个确定/取消删除确认对话框,以便从数据库中删除项目
var id=ID;
$.ajax({
type: "POST",
url: "sample.aspx?Mode=Delete",
data: { id: id },
success: function (response) {
});
你可以简单地使用Javascript的confirm
函数。这是最简单的方法:)
var r = confirm("Are you sure you want to delete this?");
if (r == true) {
var id=ID;
$.ajax({
type: "POST",
url: "sample.aspx?Mode=Delete",
data: { id: id },
success: function (response) {}
});
} else {
// Do something if they push cancel button
}
你需要使用 jquery UI 插件。 那么在 ajax 函数之前,你需要这样做:
$('a.deleteBtn').on('click', function (e) {
e.preventDefault();
** get you values here **
$('div.deleteDialog').dialog({
modal: true,
width: 400,
height: 'auto',
buttons: {
"Delete": function () {
$(this).dialog('close');
setTimeout(function () {
$.ajax({
method: 'POST',
url: url,
data: {****},
success: function () {
},
error: function () {
});
}, 1000);
},
"Cancel": function () {
$(this).dialog('close');
}
}
});
});
在 html 文件中,您需要添加对话框
<div class="deleteDialog" title="Package Delete Confirmation" style="display: none">
Are you sure you want to delete this?
</div>