简体   繁体   English

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

[英]swal().then(function ()) not firing in Internet Explorer 11

Hoping you can help me with this, I assume there is a small thing I am missing. 希望您能为我提供帮助,我想我有一个小事情想念。

My _layout.cshtml contains all the relevant scripts to have sweetheart working on IE: 我的_layout.cshtml包含所有相关脚本,可让甜心在IE上工作:

(this was working in previous versions though we haven't had to support IE for some time) (尽管以前已经不需要支持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]-->

As you can see, promise is included before sweetalert2 and I know that this is fine as the sweetalert functions on my form submit. 如您所见,在sweetalert2之前包含了sweetalert2并且我知道这很好,因为在我的表单上提交了sweetalert函数。

The issue is that when I click "Yes" the .then() function is not being hit, in debugger it is ignored and skipped straight over. 问题是,当我单击“是”时,没有点击.then()函数,在调试器中它将被忽略并直接跳过。 This is only relevant to IE, only tested in 11 at the moment I am just going to check other versions now. 这仅与IE相关,目前仅在11中进行了测试,现在我将要检查其他版本。 I cannot work out why this is happening, any ideas? 我不知道为什么会这样,有什么想法吗?

Relevant .js: 相关.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. is knockout.js bound but I am almost completely certain knockout has no part to play in this. knockout.js绑定,但我几乎完全可以肯定敲除没有任何作用。

After a lot of poking around, I realised that this needs a polyfill service. 经过一番摸索,我意识到这需要一个polyfill服务。

My IE tags were updated to: 我的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>
    }

Gotta love the 1 line fixes! 要爱1行修复!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM