0

Recently I have been trying to get my page to be able to change the content with AJAX or similar, using Javascript and without redirecting.

I found on another question they claim it can not be done and you must use a hash.

However, here, it is being done so that leads me back to wonder how it is done.

Any ideas?

Thanks.

Shane
  • 2,007
  • 18
  • 33
  • I'm not sure that I understand your question correctly, however if you only want to change content, you can rely on [jQuery's load][1] method [1]: http://api.jquery.com/load/ that can load content in a div –  Feb 15 '12 at 10:21
  • 1
    He is using the new history API, see this question: http://stackoverflow.com/questions/4952554/github-source-dynamic-navigation – Felix Kling Feb 15 '12 at 11:54

1 Answers1

0

You have the html structure like:

<div id="navigation">
  <a href="#" id="about">About Me</a>
  <a href="#" id="other">Other Stuff</a>
</div>

And you Javascript Code would be:

$('#about').on("click",function(e){
    e.preventDefault();
    //do the ajax stuff.
});

$('#other').on("click",function(e){
    e.preventDefault();
    //do the ajax stuff.
});

other examples:

mas-designs
  • 7,498
  • 1
  • 31
  • 56
  • EvilP: Ok, the problem with that is if I went to site/about or whatever it happened to be, it would not work. The only reason it works above is because navigation has been prevented. Maybe the only way around it is to also set up some sort of server-level redirection? – Shane Feb 15 '12 at 10:36
  • you can add an error block to you ajax call. So if something goes wrong, the page is not available you could do a seperate function to handle this ! – mas-designs Feb 15 '12 at 10:41