Gurjit singh Gurjit singh - 1 year ago 67
Ajax Question

after including page i am facing ajax error (Not Found)

I am working on notification system. Soi am following this blog (
Please see the code.

So it's working fine 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).

I renamed the index.php as notification.php and I am including it on my website index.php page. 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.


Please see my code below.


#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;

<script src="" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
function addmsg(type, msg) {



function waitForMsg() {

type: "GET",
url: "select.php",

async: true,
cache: false,
timeout: 50000,

success: function(data) {
addmsg("new", data);
error: function(XMLHttpRequest, textStatus, errorThrown) {
addmsg("error", textStatus + " (" + errorThrown + ")");

$(document).ready(function() {



<span id="notification_count"></span>
<a href="#" id="notificationLink" onclick="return getNotification()">Notifications</a>
<div id="HTMLnoti" style="textalign:center"></div>



<?php include "../../includes/db.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;

So after including the notification.php file in's giving me an error.
But without including this file. it's working fine.

<!-- Notification panel-->
<?php include "../includes/notification.php" ?>

Answer Source

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

    type: "GET",
    url: "select.php",

Second, you should think about splitting notification.php into three parts:

  • put CSS into main .css file
  • JavaScript code should be in notification.js
  • HTML code you can leave in notification.php

Then include notification.php in the index.php after you have included .css and .js files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download