每当成功调用以下函数1时,Sweetalert对话框在打开后立即消失,并且位置reload()起作用。当number_of_errors> 0时,它是完全相同的代码,但是在后一种情况下,sweetalert保持打开状态。成功为1时如何保持开放
注意:由于ajax调用,此函数从另一个sweetalert函数中调用。另外,成功/错误图标也不会显示:-(。。HTML中很好地引用了css和js文件
任何想法都将受到欢迎
提前致谢
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();
}
})
关于javascript - Sweetalert2 Swal火在弹出后消失。非常奇怪的错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58950870/