javascript - 通知模式未在 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.closed
从false
变为true
,但模式并没有消失。控制台中没有日志。知道有什么问题吗?
解决方案
推荐阅读
- ios - iOS界面生成器自动约束问题
- flutter - Flutter 列表返回的实例
- javascript - 3 jQuery 脚本不能在 HTML 页面中协同工作
- path - 我在哪里可以找到相对路径?
- windows - 为 WSL(1 和 2)Windows 10 设置 Ansible 主机
- java - 在测试中运行时,WireMock 总是返回 Connection Refused
- angular - Angular 库项目中没有提供程序错误
- prolog - Prolog无限重复相同的答案
- jenkins - 如何在詹金斯中将 git 提交详细信息从一项工作传播到另一项工作
- python - 如何在格式化列表中删除 tup[3] 以打印日历类型输出?