首页 > 解决方案 > 通知模式未在 n.close() 上关闭

问题描述

这个想法是检查某个页面是否每秒可用。当页面可用时,我想显示一个 Noty-modal,用户可以在其中选择重新加载当前页面或关闭模式。我使用 Noty.js v3.1.4。

JS代码

<script>
    var n = new Noty({
        text: "Website under construction",
        type: 'alert',
        layout: 'center',
        theme: 'bootstrap-v4',
        modal: 'true',
        buttons: [
            Noty.button("Yes", "btn btn-primary", function () {
                location.reload();
            }),
            Noty.button("No", "btn btn-primary ml-3", function () {
                checkAvailability = true;
                n.close();
            })],
        animation: {
            open: 'animated fadeIn faster',
            close: 'animated fadeOut faster'
        }
    });
    var checkAvailability = true;
    var timeout = 1000;
    
    (function(){
        if (checkAvailability) {    
            $.ajax({
                url: "https://example.com",
                type : 'HEAD',
                success : function(){
                    //website is available
                    checkAvailability = false;
                    timeout = 30000; // set timeout to 30 seconds, no need to check every second anymore
                    n.show();
                },
                error: function (){
                    //website is not available
                    checkAvailability = true;
                    timeout = 1000;
                }
            });
        }
        setTimeout(arguments.callee, timeout);
    })();
</script>

AJAX 请求有效,并且在某个时刻出现了 Noty Modal。现在,当我单击“否”时,模式不会关闭。我看到n.closedfalse变为true,但模式并没有消失。控制台中没有日志。知道有什么问题吗?

标签: javascriptjquerynoty

解决方案


推荐阅读