swal().then(function ()) 在 Internet Explorer 11 中未触发

Gli*_*tor 4 javascript internet-explorer sweetalert2

希望你能帮我解决这个问题,我想我遗漏了一件小事。

我的_layout.cshtml包含所有相关脚本,让甜心在 IE 上工作:

(这在以前的版本中有效,尽管我们有一段时间不必支持 IE)

@if (Request.Browser.Browser == "IE" || Request.Browser.Browser == "InternetExplorer")
{
    <script src="https://npmcdn.com/es6-promise@3.2.1"></script>
}
<script type="text/javascript" src="~/bower_components/sweetalert2/dist/sweetalert2.min.js"></script>

<!--[if IE 9]>
    <script src="~/bower_components/sweetalert2-ie9/dist/sweetalert2.min.js"></script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

如您所见,promise 之前包含在内sweetalert2,我知道这很好,因为我的表单上的 sweetalert 函数提交。

问题是,当我单击“是”时,该.then()函数没有被命中,在调试器中它被忽略并直接跳过。这个只和IE有关,目前只在11中测试过,我现在就去看看其他版本。我无法弄清楚为什么会发生这种情况,有什么想法吗?

相关.js:

vm.PostCommentData = function (postData, event) {
    var $commentTextBoxId = '#' + vm.createRemedyCommentId;

    if ($($commentTextBoxId).length) {
        var globalTranslations = globalDashboard.GetTranslations();

        swal({
            title: translations.AreYouSureYouWantToSubmit,
            text: '',
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: '<i class="fas fa-thumbs-up"></i> ' + globalTranslations.Yes,
            cancelButtonText: '<i class="fas fa-thumbs-down"></i> ' + globalTranslations.No,
            confirmButtonClass: 'btn btn-success',
            cancelButtonClass: 'btn btn-danger',
            buttonsStyling: false
        }).then(function () {
            vm.state($(event.currentTarget).data('state'));
            var newComment = $($commentTextBoxId).val();
            var errorMessage = $("<ul class='list-unstyled' />");
            var hasErrored = false;

            if (vm.selectedQuestions().length == 0) {
                errorMessage.append("<li>" + translations.AtLeastAQuestionIsRequiredToBeSelected + "</li>");
                hasErrored = true;
            }

            if (vm.selectedDealershipId() == undefined) {
                errorMessage.append("<li>" + translations.PleaseSelectADealership + "</li>");
                hasErrored = true;
            }

            if (newComment === '') {
                errorMessage.append("<li>" + translations.CommentTextIsRequired + "</li>");
                hasErrored = true;
            }

            if (hasErrored) {
                swal({
                    title: translations.Warning,
                    html: errorMessage,
                    type: 'error',
                    buttonsStyling: false,
                    confirmButtonText: '<i class="fas fa-check"></i> ' + globalTranslations.OK,
                    confirmButtonClass: 'btn btn-success'
                });
            }
            else {

                var successMessage = translations.YourRemedyHasBeenSubmitted;
                if (vm.selectedQuestions().length > 1)
                    successMessage = translations.YourRemediesHaveBeenSubmitted;

                swal({
                    title: translations.Completed,
                    text: vm.globalViewModel().decodeEntities(successMessage),
                    type: 'success',
                    buttonsStyling: false,
                    confirmButtonText: '<i class="fas fa-check"></i> ' + globalTranslations.OK,
                    confirmButtonClass: 'btn btn-success'
                }).then(function () {
                    $(remedyBoxId + " .overlay").show();
                    $('#create-remedy-commentFormId').submit();
                });
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

vm.knockout.js必然的,但我几乎完全确定淘汰赛在这方面没有任何作用。

Gli*_*tor 5

经过大量的摸索,我意识到这需要一个 polyfill 服务。

我的 IE 标签更新为:

@if (Request.Browser.Browser == "IE" || Request.Browser.Browser == "InternetExplorer")
    {
        <script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
        <script src="https://npmcdn.com/es6-promise@3.2.1"></script>
    }
Run Code Online (Sandbox Code Playgroud)

必须喜欢 1 行修复程序!