Reputation: 15949
I have tried to make a very simple script for loading pages in wordpress -
<script>
jQuery(document).ready(function(){
// ajax pagination
jQuery('.navigation a').live('click', function(){ // wp pagination link on default theme
var link = jQuery(this).attr('href');
// #content is the content wrapper
jQuery('#content').append('<div><h2>Loading...</h2></div>');
// .entry is a single post wrapper
jQuery('#content').append(link+'.entry')
});
}); // end ready function
</script>
tried also :
jQuery('#content').load(link+'.entry')
and
//tried also .load.ajax and prepend.ajax
jQuery('#content').prepend.ajax({
url: link,
});
somehow they all work the same, I do see a "loading" div, but then the page gets refreshed with the new posts - I can not seem to append it to the end , or to the div that I need..
Upvotes: 0
Views: 925
Reputation: 293
Your second attempt was correct but if you're targetting an element within the page you're requesting there needs to be a space between the URL and the selector, so instead of this:
jQuery('#content').load(link + '.entry');
Do this:
jQuery('#content').load(link + ' .entry');
That will grab the element .entry
and asynchronously load it into #content
.
Upvotes: 1