[英]Jquery and ajax delete conformation box
i need a ok / cancel delete confirmation dialogue box before i send ajax request in order to remove item from database 我需要一个确定/取消删除确认对话框,然后再发送ajax请求才能从数据库中删除项目
var id=ID;
$.ajax({
type: "POST",
url: "sample.aspx?Mode=Delete",
data: { id: id },
success: function (response) {
});
You can simply use Javascript's confirm
function. 您可以简单地使用Javascript的
confirm
功能。 This is the easiest approach :) 这是最简单的方法:)
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
}
You need to use jquery UI plugins. 您需要使用jquery UI插件。 Then just before the ajax function you need to do this:
然后,在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');
}
}
});
});
In youy html file you need to add the dialog 在您的html文件中,您需要添加对话框
<div class="deleteDialog" title="Package Delete Confirmation" style="display: none">
Are you sure you want to delete this?
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.