[英]After including page I am facing ajax error (Not Found)
I am working on notification system. 我正在使用通知系统。 So I am following this blog ( http://www.phptutorials.club/ajax-notification-in-php-with-example/ ).
因此,我正在关注此博客( http://www.phptutorials.club/ajax-notification-in-php-with-example/ )。 Please see the code.
请查看代码。
It's working fine and it's giving me a notification, but the problem is if I include the page in another index.php page, then it's giving me (error (Not Found). 它工作正常,正在向我发出通知,但是问题是,如果我将该页面包含在另一个index.php页面中,那么它将给我(错误(未找到)。
I renamed the index.php as notification.php and I am including it on my website index.php page. 我将index.php重命名为notification.php,并将其包含在我的网站index.php页面中。 So after including it's giving me an error but without including it's working fine.
因此,包含它后给我一个错误,但不包含它就可以正常工作。
Please suggest I know PHP but don't know about ajax and jquery,js. 请建议我知道PHP,但不了解ajax和jquery,js。
Please see my code below. 请在下面查看我的代码。
notification.php 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 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);
?>
So after including the notification.php file in index.php.it's giving me an error. 因此,在将index.php。中包含notification.php文件之后,它给了我一个错误。 But without including this file.
但不包括此文件。 it's working fine.
工作正常。
<!-- Notification panel-->
<?php include "../includes/notification.php" ?>
First check if your include path is correct. 首先检查您的包含路径是否正确。 Try:
尝试:
<?php include "../../includes/notification.php" ?>
Additionally, check the path to select.php
in your ajax call 另外,在ajax调用中检查
select.php
的路径
$.ajax({
type: "GET",
url: "select.php",
...
Second, you should think about splitting notification.php into three parts: 其次,您应该考虑将notification.php分为三个部分:
Then include notification.php in the index.php after you have included .css and .js files. 然后,在包含.css和.js文件之后,将notification.php包含在index.php中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.