每当成功调用以下函数时,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
});
}
}
}