通过 ajax 在网站上提醒用户
Alerting users on website through ajax
我正在尝试制作一个通知系统,当用户被分配到工单或将新工单添加到数据库时通知用户。
我已经拥有的系统本身可以工作,只是它只将通知发送给收到 ajax 请求的第一个用户。有没有办法让每个应该收到通知的人都真正收到通知?
我的代码:JavaScript:
function checkUpdates()
{
$.ajax({
type: "POST",
url: 'ajax/checkDB.php', // a webservice or other URL that queries the database
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
console.log('Connected and executed PHP page... '+data);
if (data.hasChanged == "true") {
playSound('img/notif2');
notifyAdmin();
console.log('Updated Tickets Page...');
$("#contents").load("dynamic/tickets.php");
$("#contents").fadeTo("fast", 1);
}
if (data.newAssigned == "true") {
playSound('img/notif2');
notifyUser();
console.log('Updated Tickets Page...');
$("#contents").load("dynamic/tickets.php");
$("#contents").fadeTo("fast", 1);
}
}
});
}
$(document).ready(function() {
setInterval("checkUpdates()", 3000); // Calls the function every 3 seconds
});
我的php脚本(checkDB.php):
<?php
include("../static/config.php");
session_start();
header("Content-Type: text/json");
$result = mysqli_query($con,"SELECT notify FROM tickets WHERE notify='0'");
$row_cnt = mysqli_num_rows($result);
if($row_cnt > 0) {
$hasChanged = 'true';
mysqli_query($con,"UPDATE tickets SET notify='1' WHERE notify='0'");
} else {
$hasChanged = 'false';
}
$result2 = mysqli_query($con,"SELECT notify,Assigned FROM tickets WHERE Completeness='1' AND notify='1'");
$row_cnt2 = mysqli_num_rows($result2);
if($row_cnt2 > 0) {
while($row2 = mysqli_fetch_array($result2))
{
if(strcmp($_SESSION['Name'],$row2['Assigned']) == 0) {
$newAssigned = 'true';
} else {
$newAssigned = 'false';
}
}
mysqli_query($con,"UPDATE tickets SET notify='2' WHERE Completeness='1' AND notify='1'");
} else {
$newAssigned = 'false';
}
echo json_encode(array('newAssigned' => $newAssigned, 'hasChanged' => $hasChanged));
?>
以下是我的确切意图的概要:用户登录到系统,如果授予管理权限,则被授予管理权限。用户加载工单页面,其中列出了所有工单以及我给你的这个 javascriptJavaScript 每 3 秒加载一次 checkDB.php基本上是对数据库运行 'notify' 值为 0 的检查,如果至少存在 1,则在数据库中更新为 '1' 并返回为 true 给 ajax 调用 - 它发出通知。
同样,这适用于加载到页面中的第一个用户,但在那之后,显然数据库中不再有"notify=0",因为它们已经更新,因此不会显示通知。
有人要求我共享我的数据库结构。票:
UniqueID - Unique ID per ticket (always unique)
Requester - Whoever submitted the ticket.
Problem - Description of the given issue.
Assigned - User who is assigned to the ticket.
Completeness - The level of completeness (0-4)
Times - Times listed for ticket start, assigned, etc
notified - Used in old ticket system (I plan to get rid of it)
Urgency - Selected by requester, how urgent the ticket is
Location - Location in our warehouse assistance is needed.
FollowUp - currently not in use, will be used to submit follow ups.
isProject - (0-1) is project or not
additionalTechs - Lists additional users on a ticket (Not important for question)
notify - (0-2) at 0, ticket is new and notif should be sent to admins which should set this to 1, when it is 1 it should send a notif to users that are attached to the ticket.
技术数据库:
UniqueID
Username
Password
Name
Level
Disabled
LastTimeSeen
needsNotify (Used in old system, plan to remove)
我真的被困在这里了。
你可以
用websockets或 socket.io 来制作。然后多个客户端的js将与该套接字连接,将通知所有连接的人有关他们的票证
您可以将更新语句更改为以下内容:
UPDATE tickets SET notify='1' WHERE notify='0' and Assigned = ''//some user id passed
相关文章:
- 为所有查看网站的用户保存变量
- 如果用户回答是,我想关闭网站
- 如何让iPhone用户在我的网站上观看带字幕的视频
- 如何制作交互式网站并允许用户编辑网站内容
- 使用谷歌分析'Wordpress网站的用户ID功能
- 在用户滚动时加载单个页面网站的不同部分
- 检测用户关闭标签页或离开网站
- 如何创建一个提示用户输入登录id和密码的网站
- 实现已验证用户更新状态的最佳方式,作为对系统中已更改状态的反应.(ASP.NET MVC网站)
- 为网站创建用户生成的文本
- 检查用户在网站上使用的平台
- 如何获取我的网站(我的服务器)用户的MAC地址
- 用户在网站上创建和管理菜单
- 我正在尝试为一个网站创建一个文本框,可以将文本更改为用户希望的任何格式
- 如何在用户缩放我的网站时修复字体大小(CTRL+'+')
- 如何在我的网站上获得用户在线状态(实时)
- 允许用户键入html标签并将其保存到文件中以在网站上显示
- 根据用户在asp.net网站中选择的弹出窗口使用JavaScript操作网页
- 防止Angular网站上未经授权的用户在重定向到登录之前看到网站的最佳方式
- 如何在网站上实现一个按钮,允许用户将生成的数组数据保存为ASCII文件