【发布时间】:2015-04-21 09:38:11
【问题描述】:
所以我试图弄清楚这段 JavaScript。我正在尝试做的事情是使用查询来显示我的数据库中的通知数量。因此,假设我的数据库中有 5 个通知,是否可以向此代码添加查询,以便显示如下内容:你好,你有 5 条未见过的消息?我现在已经搜索了几个小时,这让我发疯了。
提前致谢
<html>
<head>
<script language="javascript">
function notifyMe() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user is okay, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
// At last, if the user already denied any notification, and you
// want to be respectful there is no need to bother them any more.
}
</script>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div><button onclick="notifyMe()">Meldingen ophalen</button></div>
</body>
</html>
【问题讨论】:
-
完成此任务的最简单方法是执行 xmlhttprequest ... 每分钟左右说一次?检查是否有可用的更新。
标签: javascript html sql database