最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - swal().then(function ()) not firing in Internet Explorer 11 - Stack Overflow

programmeradmin0浏览0评论

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:

(this was working in previous versions though we haven't had to support IE for some time)

@if (Request.Browser.Browser == "IE" || Request.Browser.Browser == "InternetExplorer")
{
    <script src="/[email protected]"></script>
}
<script type="text/javascript" src="~/bower_ponents/sweetalert2/dist/sweetalert2.min.js"></script>

<!--[if IE 9]>
    <script src="~/bower_ponents/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.

The issue is that when I click "Yes" the .then() function is not being hit, in debugger it is ignored and skipped straight over. This is only relevant to IE, only tested in 11 at the moment I am just going to check other versions now. I cannot work out why this is happening, any ideas?

Relevant .js:

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

    if ($($mentTextBoxId).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 = $($mentTextBoxId).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-mentFormId').submit();
                });
            }
        });
    }
}

vm. is knockout.js bound but I am almost pletely certain knockout has no part to play in this.

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:

(this was working in previous versions though we haven't had to support IE for some time)

@if (Request.Browser.Browser == "IE" || Request.Browser.Browser == "InternetExplorer")
{
    <script src="https://npmcdn./[email protected]"></script>
}
<script type="text/javascript" src="~/bower_ponents/sweetalert2/dist/sweetalert2.min.js"></script>

<!--[if IE 9]>
    <script src="~/bower_ponents/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.

The issue is that when I click "Yes" the .then() function is not being hit, in debugger it is ignored and skipped straight over. This is only relevant to IE, only tested in 11 at the moment I am just going to check other versions now. I cannot work out why this is happening, any ideas?

Relevant .js:

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

    if ($($mentTextBoxId).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 = $($mentTextBoxId).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-mentFormId').submit();
                });
            }
        });
    }
}

vm. is knockout.js bound but I am almost pletely certain knockout has no part to play in this.

Share asked Jan 19, 2018 at 11:22 Glitch_DoctorGlitch_Doctor 3,0343 gold badges18 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

After a lot of poking around, I realised that this needs a polyfill service.

My IE tags were updated to:

@if (Request.Browser.Browser == "IE" || Request.Browser.Browser == "InternetExplorer")
    {
        <script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
        <script src="https://npmcdn./[email protected]"></script>
    }

Gotta love the 1 line fixes!

发布评论

评论列表(0)

  1. 暂无评论