启动通知在本地工作,但不在服务器中



我在本地主机应用程序中设置了通知,一切都很正常。我上传到服务器,通知不会显示,即使没有任何更改。

我有两个文件-

  1. notifications.php,用于准备显示输出
  2. fetch-notifications.php,它实际上检查是否有可用的通知,并传递到notifications.php

我在相关文件中包含notifications.php,并确认此部分确实有效。当我检查调试时,我可以看到notifications.php肯定在使用正确的路径调用正确的文件。

任何帮助都将不胜感激——我被困在这里了!

通知.php

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
#alert_popover
{
display:block;
position:absolute;
right:15px;
top:0px;
z-index: -1;
}
.wrapper {
display: table-cell;
vertical-align: bottom;
height: auto;
width:200px;
z-index: -1;
}
</style>
<div id="alert_popover">
<div class="wrapper">
<div class="content">
</div>
</div>
</div>
<script>
$(document).ready(function(){
setInterval(function(){
load_last_notification();
}, 5000);

function load_last_notification()
{
$.ajax({
url:"/cl/includes/fetch-notifications.php",
method:"POST",
success:function(data)
{
$('.content').html(data);
}
})
}
});
</script>

获取通知.php


include 'db.php';
include 'security.php';
$userID = $_SESSION['userID'];
$output = '';
$db = new db();
$query = $db->query("SELECT * FROM notifications WHERE status = '0' AND targetUserID = '$userID'");
if ($query->numRows() > 0) {
$query = $db->query("SELECT * FROM notifications WHERE status = 0 AND targetUserID = '$userID' ORDER BY notificationID ASC LIMIT 1")->fetchAll();
foreach ($query as $result) {
$hasLink = $result['hasLink'];
$popupClass = $result['popupClass'];
if ($hasLink == 1) {
$entity = $result['entity'];
$entityID = $result['entityID'];
switch ($entity) {
case 'voyage':
$link = "/cl/unit/view?voyageID=$entityID";
break;
case 'vessel':
$link = "/cl/unit/view?vesselID=$entityID";
break;
case 'vesselReport':
$link = "/cl/unit/view/reports/view?reportID=$entityID";
break;
case 'vesselReportDraft':
$link = "/cl/unit/view/reports/draft/view?reportID=$entityID";
break;
}
}
$now = date("Y-m-d H:i:s");
$createTimestamp = $result['createTimestamp'];
$minutes = (time() - strtotime($createTimestamp));
$start_date = new DateTime($createTimestamp);
$since_start = $start_date->diff(new DateTime($now));
if ($since_start->days > 0) {
$timeDisplay = $since_start->days . " days ago";
} elseif ($since_start->h >= 1) {
$timeDisplay = $since_start->h . " hours ago";
} elseif ($since_start->m >= 1) {
$timeDisplay = $since_start->m . " mins ago";
} else {
$timeDisplay = "Just Now";
}
if (empty($popupClass)) {
$popupClass = 'info';
}
$output .= '
<div class="alert alert-' . $popupClass . '">
<a class="close" data-dismiss="alert" aria-label="close">&times;</a>
<p><strong>' . $result["subject"] . '</strong>
<br>
' . $result["notification"] . ' <br><small><i>' . $timeDisplay . '</small></i>
</p>';
if ($hasLink == 1) {
$output .= "<a href='$link'><button type='button' class='btn btn-white btn-block'>View</button></a>";
}
$output .= '</div>
';
$notificationID = $result['notificationID'];
$query = $db->query("UPDATE notifications SET status = '0', readTimestamp = '$now' WHERE notificationID = '$notificationID'");
$notificationID = '';
}
}

echo $output;

用于在服务器中使用Ajax。您应该添加JQUERY。在HTML文件中。头内标签例如:

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

当我在Windows环境中开发并部署在Linux环境中时,类似的场景也发生在我身上。常见的问题是,

  1. 权限问题(使用浏览器控制台,确保/cl/includes/fetch-notifications.php从服务器返回数据(
  2. 区分大小写问题(检查所有PHP变量和MySQL字段名称是否正确。它们在Linux环境中区分大小写(

最新更新