1

after i used jquery.load() it doesnt read the includes on index.php and makes home.php unreadable, heres my sample code. but if i manually added the contents of sqlcon.php on home.php it works, how can i fix this?

index.php

require 'sqlcon.php';
include 'portal.php';

portal.php

<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/ajax.js" type="text/javascript"></script>
<div id="nav">
<ul>
<li><a href="modules/menu/home.php" class="nav">Home</a></li>
<li><a href="modules/menu/setup.php"  class="nav"> Setup</a></li>
</ul>
</div>
<div id="subnav"></div>

home.php

$result = mysql_query("SELECT announcement_date,announcement_title,announcement_text FROM sp_announcement") or die(mysql_error());  


    echo "<table id=\"newspaper-b\">";
    echo "<thead>";
    echo "<tr>";
    echo "<th scope=\"col\">Date</th>";
    echo "<th scope=\"col\">Title</th>";
    echo "<th scope=\"col\">Announcement</th>";
    echo "</tr>";
    echo "</thead>";

    while($row = mysql_fetch_array( $result )) {
            echo "<tr>";
            echo '<td>' . $row['announcement_date'] . '</td>';
            echo '<td>' . $row['announcement_title'] . '</td>';
            echo '<td>' . $row['announcement_text'] . '</td>';
            echo "</tr>"; 
    } 
    echo "</table>";
    echo "<br>";
    echo "<br>";

ajax.js

$(document).ready(function() {
$('a.nav').click(function() {
var url = $(this).attr('href');
$('#subnav').load(url);
return false;
});
});
3
  • Did you deliberately not paste the starting <?php-tag? Commented Feb 13, 2013 at 18:48
  • Also, define "makes home.php unreadable" Commented Feb 13, 2013 at 18:49
  • @hank i ddnt include it, but its on the actual file. Well Home.php doesnt read the include sqlcon.php and it just shows nothing Commented Feb 13, 2013 at 19:03

2 Answers 2

1

Could it be that the php script is assuming the directory location of the javascript file that's calling it? In which case, you'll want to write the paths of the included files relative to the current working directory when it's loaded through the js.

To find the current directory, try putting this all the way on the top of your php file. (before the includes):

echo "Current Directory: " . getcwd();
exit;
Sign up to request clarification or add additional context in comments.

Comments

1

Just a guess here, but your file links at the top are probably not being resolved.

You should be writing them as

<script src="/js/jquery.js" type="text/javascript">

instead of

<script src="js/jquery.js" type="text/javascript">

The logic being the relative link in include could now mean something different if youre putting included files in a /includes/ folder or something similar.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.