Load external pages using jquery

Posted by user1688011 on Stack Overflow See other posts from Stack Overflow or by user1688011
Published on 2012-09-21T07:11:55Z Indexed on 2012/09/21 9:38 UTC
Read the original article Hit count: 299

Filed under:
|
|
|

I'm trying to use jquery to load external pages into the current without reloading. Apparently everything works fine except of one little issue, I hope I'll be clear as much as possible. When I call the page 'info.php' it is loaded into the #content div. That's what the script supposed to do, the problem is that in the main page, which contains the script and the #content div, I already have some code that I want it to be executed when someone visit the page and not to be called from external page. That is actually the case but when I click on one of the links in the menu, I can't go back to the initial content..

<script>
$(function() {
   $('#nav a').click(function() {
    var page = $(this).attr('href');
    $('#content').load(page + '.php');
    return false;
    });
});
</script>

<ul id="nav">
<li><a href="#">Page1</a></li>
<li><a href="about">About</a></li>
<li><a href="contact">Contact</a></li>
<li><a href="info">Info</a></li>
</ul>

<div id="content">
Here I have some code that I wanted to be attributed to the "Page1"
</div>

Do you have any suggestions how to fix this issue? Thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery