【发布时间】:2016-08-19 04:39:35
【问题描述】:
我正在开发通知系统。所以我关注这个博客(http://www.phptutorials.club/ajax-notification-in-php-with-example/)。 请看代码。
它工作正常,它给我一个通知,但问题是如果我将该页面包含在另一个 index.php 页面中,那么它会给我(错误(未找到)。
我将 index.php 重命名为 notification.php,并将其包含在我的网站 index.php 页面中。所以在包含它之后会给我一个错误但不包含它工作正常。
请建议我了解 PHP 但不了解 ajax 和 jquery,js。
请看下面我的代码。
notification.php
<style>
#notification_count {
padding: 0px 3px 3px 7px;
background: #cc0000;
color: #ffffff;
font-weight: bold;
margin-left: 77px;
border-radius: 9px;
-moz-border-radius: 9px;
-webkit-border-radius: 9px;
position: absolute;
margin-top: -1px;
font-size: 10px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
function addmsg(type, msg) {
$('#notification_count').html(msg);
}
function waitForMsg() {
$.ajax({
type: "GET",
url: "select.php",
async: true,
cache: false,
timeout: 50000,
success: function(data) {
addmsg("new", data);
setTimeout(
waitForMsg,
1000
);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
addmsg("error", textStatus + " (" + errorThrown + ")");
setTimeout(
waitForMsg,
15000);
}
});
};
$(document).ready(function() {
waitForMsg();
});
</script>
<span id="notification_count"></span>
<a href="#" id="notificationLink" onclick="return getNotification()">Notifications</a>
<div id="HTMLnoti" style="textalign:center"></div>
<script>
</script>
select.php
<?php include "../../includes/db.php" ?>
<?php
$sql = "SELECT * from comments where comment_status = 'unapproved'";
global $connection;
$select_comments= mysqli_query($connection, $sql) or die('Could not look up user information; ' . mysqli_error($connection));
$count = mysqli_num_rows($select_comments);
echo $count;
mysqli_close($connection);
?>
所以在 index.php.it 中包含 notification.php 文件后,它给了我一个错误。 但不包括这个文件。它工作正常。
<!-- Notification panel-->
<?php include "../includes/notification.php" ?>
【问题讨论】:
-
也添加您的代码
-
请发布您的示例代码,以便我们为您提供帮助
-
已添加代码。请看
标签: javascript php jquery ajax jquery-ui