Is it possible to load all the links with class 'ajax' without refreshing the page? The complete body content should be changed, the page title and the url should so it can be bookmarked.
-
1Have a look at pjax pjax.heroku.comDogbert– Dogbert2011-07-28 10:42:56 +00:00Commented Jul 28, 2011 at 10:42
-
@Dogbert that script is massive for what effectively should a few lines of jQuery. edit- The example on the sites homepage doesn't even work.Dunhamzzz– Dunhamzzz2011-07-28 10:51:20 +00:00Commented Jul 28, 2011 at 10:51
-
1@Dunhamzzz, it does but you have to tick the checkbox. Agreed though, too much.rickyduck– rickyduck2011-07-28 11:04:35 +00:00Commented Jul 28, 2011 at 11:04
Add a comment
|
2 Answers
This should work for all links with a certain class, 'target' is the id of your main content div. It requires no editing of your current mark up.
$('.class').click(function(e) {
e.preventDefault();
$('#target').load($(this).attr('href'));
});
5 Comments
rickyduck
For the difference between my response and Dunhamzzz, read this: stackoverflow.com/questions/1246137/…
Dunhamzzz
@rickyduck .load is fine for OPs needs?
rickyduck
thought it relevent to highlight the difference for future ref, knowledge is key! $.load is fine though, I'd use $.load in this instance
esafwan
But can i change the page title and url with this?
Dunhamzzz
Yeah, depends how you want to do it, it will require some jQuery knowledge. Personally, I'd put the page title in the
<a title="" attribute, or you could be more advanced and fetch it from the ajax reponse.