开发者

JQuery Ajax with back button

How do I handle navigation with Jquery Ajax?

For eg. I开发者_开发问答 have a home page. 2 ajax link that loads the content of either page1 and page2.

I'd like the url to be: localhost/page1 or localhost/page2. I know this is possible but I do not know the name of this feature.

Coded examples would be nice.

<div id="nav">
    <a href="page1">Page 1</a> | <a href="page2">Page 2</a>
</div>
<div id="Container"></div>


You can change the window.location value to reflect your page changes.

Once you know your page you can do something like this:

var location = window.location.toString();
var pageHash = "#" + page;

if (window.location.hash == "") {
    window.location = location + pageHash;
}
else {
    window.location = location.substring(0, location.indexOf("#")) + pageHash;
}


I am just guesing if you are looking for some thiing like this

$("#nav>a").click(function(e){
 $.get($(this).attr("href"),function(data){
  $("#Container").html(data);
 });
 return false;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜