swal()。然后(function())没有在Internet Explorer 11中触发

时间:2018-01-19 11:22:25

标签: 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]-->

正如您所见,承诺包含在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();
                });
            }
        });
    }
}

vm.已被knockout.js绑定,但我几乎完全确定淘汰赛中没有任何参与。

1 个答案:

答案 0 :(得分:3)

经过大量的讨论,我意识到这需要一个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>
    }

喜欢1行修复!