[英]Alert box once logged in that there's a new record inserted on a table
我正在研究此员工管理系统及其请假系统功能。 员工提出请假申请后,当管理员登录EMS时,系统将通知他有新的请假申请。
那可能吗?
管理员登录后,您需要调用ajax函数来检查是否添加了新的请假条目。 示例代码如下。
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
(function($)
{
$.ajax(
{
url : 'server.php',
dataType : 'json',
beforeSend : function()
{
// show loading or else
},
success : function(response)
{
if(response)
{
// display it in right side div.
}
}
});
});
</script>
server.php
<?php
//database connections
$query = mysqli_query("select * from leave_table where status = 0")or die(mysqli_error());
//status 0 to check if entry is previously seen or not.
$response = array();
while($row = mysql_fetch_assoc($query))
{
$response = $row;
}
echo json_encode($response);
exit;
?>
为了每次都检查新条目,您所要做的就是将ajax调用作为函数,并通过setInterval将该函数调用所需的秒数。
另外一种替代方法是使用COMET AJAX 。
随便问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.