【发布时间】:2019-07-18 21:06:39
【问题描述】:
我正在使用 SweetAlert 库删除记录,我希望在用户单击删除按钮时出现警告消息。当我按下删除按钮时出现消息,然后执行删除,我想避免这种情况,我只想在用户确认时执行它。
我用 Jquery 和 Ajax::
做了这个动作<script>
$(document).ready(function () {
$(".btn-eliminar").on("click", function () {
Swal.fire({
title: 'Are you sure you want to delete this Chat?',
text: "You will not be able to recover the data!",
type: 'warning',
showCloseButton: true,
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'Cancel'
}).then(function (isConfirm) {
if (isConfirm) {
Swal.fire(
'Removed!',
'A chat was deleted.',
'success'
).then(function () {
$.ajax({
type: "POST",
url: '@Url.Action("DeleteChat", "Chat")',
data: { id: $(this).parent().siblings(".td-id").text().trim() },
success: function (rpta) {
},
error: function (req, textStatus, errorThrown) {
alert('Ooops, something happened: ' + textStatus + ' ' + errorThrown);
}
});
});
} else {
}
});
});
});
【问题讨论】:
标签: jquery ajax asp.net-mvc sweetalert2