Good day all,
I've been looking for a solution for ages but still haven't found any.
I'm building a platform and I'm using jQuery to refresh a div in one of my pages. I know the refresh is working because when I .load()
a simple page it's working.
The jQuery code I'm using is:
$('.refreshDIV').load('/pages/extra/results.php');
I also tried:
$('.refreshDIV').load('/pages/extra/results.php' + location.search);
The first line in results.php
is:
<?php
if (!defined('INDEX')) {
require('../../includes/config.php');
header('Location: /');
exit;
}
When I click the button to refresh the .refreshDIV
it redirects me back to /
, which assumes that INDEX
is not defined and that the loaded page is being loaded as a "standalone" page.
When I comment out the first line I see an error 500
in the console which seems to assume that the PHP code on that page is not working (it is depending on other pages).
The page with the div that needs to be refreshed looks like this:
<div class="refreshDIV">
<?php include('pages/extra/results.php'); ?>
</div>
The page itself is working fine, but like I said when I click the button to refresh the div I get redirected back to /
.
Does anyone know what I'm doing wrong here?
From your comments, it seems that you did not set the constant INDEX
, which is set in the index.php
.
The condition !defined('INDEX')
will always return true
.
As a result the code header('Location: /');
will be executed, which will redirect you to the new page instead of loading the content.
You need to either define the constant in the results.php
or remove the check !defined('INDEX')
.