Sweetalert2弹出后,小火消失 。非常奇怪的错误

问题描述 投票:0回答:1

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

注意:由于ajax调用,此函数从另一个sweetalert函数被调用。另外,成功/错误图标也不会显示:-(。。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
            });
        }
    }
}

[每当成功调用以下函数时,Sweetalert对话框在打开后立即消失,并且位置reload()起作用。当number_of_errors> ...

javascript sweetalert sweetalert2
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.