【发布时间】:2021-03-02 01:48:46
【问题描述】:
给定这样的表单 ajax
<form method="post"
data-ajax="true"
data-ajax-method="post"
data-ajax-complete="completed"
data-ajax-confirm="Are you sure you want to do this?">
<input type="text" name="name" /><input type="submit"/>
</form>
我已经设置了data-ajax-confirm,但是知道如何使用 sweetalert 来实现吗?
例子
<script>
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
//Submit ajax here
} else {
swal("Your imaginary file is safe!");
}
});
completed = function (xhr) {
if (xhr.status == "200") {
swal("Success", xhr.responseText, "success")
.then(() => {
location.reload();
});
}
else {
swal("Error", xhr.responseText, "error")
}
};
</script>
如何在提交前显示带有sweetalert的对话框
【问题讨论】:
-
sweetalert 是在哪里定义的?
标签: jquery asp.net-core razor-pages unobtrusive-ajax