Sweetalert2 Swal火焰在弹出后消失.非常奇怪的错误



只要以下函数调用成功1,Sweetalert对话框就会在打开后立即消失,位置reload((也会起作用。当number_of_errors>0时,它是完全相同的代码,但在后一种情况下,sweetalert保持打开状态。当成功是1 时,我如何保持开放

注意:这个函数是从另一个sweetalert函数调用的,这是ajax调用的结果。此外,成功/错误图标不会显示:-(.css和js文件在HTML 中得到了很好的引用

欢迎有任何想法,请

提前感谢

function show_comment_result(
success,
number_of_errors,
error_messages,
action
) {
if (action == "new item") {
html_success = "The item was successfully added";
html_errorA =
'<p>We had an <font color="#ff0000">error</font>: <p>' +
'<p><font color="#ff0000">' +
error_messages +
'</font></p><b><a href="#" id="temp2" onclick="restart_entry(); ">Please Try Again</a></b>';
html_errorB =
'<p> <font color="#ff0000">UNKNOWN error occured</font>: <p><b><a href="#" id="temp2" onclick="restart_entry(); ">Please Try Again</a></b>';
} else if (action == "edit item") {
html_success = "The item was successfully edited";
html_errorA =
'<p>We had an <font color="#ff0000">error</font>: <p>' +
'<p><font color="#ff0000">' +
error_messages +
"</font></p>";
html_errorB = '<p> <font color="#ff0000">UNKNOWN error occured</font>';
} else if (action == "delete item") {
html_success = "The item was successfully deleted";
html_errorA =
'<p>We had an <font color="#ff0000">error</font>: <p>' +
'<p><font color="#ff0000">' +
error_messages +
"</font></p>";
html_errorB = '<p> <font color="#ff0000">UNKNOWN error occured</font>';
}
if (success == 1) {
Swal.fire({
type: "success",
title: "Success!",
icon: "success",
showConfirmButton: true,
html: html_success
});
if (action == "edit item" || action == "delete item") {
location.reload();
} else if (action == "new item") {
document.getElementById("HiddenForm").reset();
}
//$('#HiddenForm')[0].reset();
if (action == "new item") {
document.getElementById("HiddenForm").reset();
}
} else {
if (number_of_errors > 0) {
Swal.fire({
icon: "error",
titleText: "Ooops",
title: "Ooops...",
showConfirmButton: false,
html: html_errorA
});
} else {
Swal.fire({
icon: "error",
showConfirmButton: false,
titleText: "Ooops",
title: "Ooops...",
html: html_errorB
});
}
}
}

您可以这样做:

Swal.fire({
type: "success",
title: "Success!",
icon: "success",
showConfirmButton: true,
html: html_success
}).then(() => {
if (action == "edit item" || action == "delete item") {
location.reload();
} else if (action == "new item") {
document.getElementById("HiddenForm").reset();
}
//$('#HiddenForm')[0].reset();
if (action == "new item") {
document.getElementById("HiddenForm").reset();
}
})

最新更新