这个想法是检查某个页面是否每秒可用。当页面可用时,我想显示一个 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.closed
从false
变为true
,但模式并没有消失。控制台中没有日志。知道有什么问题吗?