有没有人可以帮我ajax分页,我已经在它上面2天了,还不能弄清楚。我已经加载了更多的样式分页,这是代码,精确经典(下文)。除了占位符到达第10页之外,一切都像计划一样工作。然后,地狱松开了,什么都不再加载了。该按钮在到达maxpages之前仍然有效,因此该按钮被移除,但超过10个占位符时不会发生任何事情。我目前正在使用这个脚本的网站,你可以测试自己的地方是这样的:http://filmhdonline.com/category/toate-filmele/,如果有人对我所说的有一个想法,我会很感激。提前谢谢。
jQuery(document).ready(function() {
// The number of the next page to load (/page/x/).
var pageNum = parseInt(pbd_alp.startPage);
// The maximum number of pages the current query can return.
var max = parseInt(pbd_alp.maxPages);
// The link of the next page of posts.
var nextLink = pbd_alp.nextLink; pageNum++;
//Load more videos translation
var more = pbd_alp.more;
//Loading videos translation
var loading = pbd_alp.loading;
/**
* Replace the traditional navigation with our own,
* but only if there is at least one page of new posts to load.
*/
if(pageNum <= max) {
// Remove the traditional navigation.
jQuery('.pagination').remove();
// Insert the "More Posts" link.
if( jQuery('#content').find('ul.listing-videos').length == 1 ){
jQuery('#content ul.listing-videos').append('<li class="more-posts pbd-alp-placeholder-' + pageNum + '"></li>');
jQuery('#content').append('<p id="pbd-alp-load-posts" class="pagination"><a href="#">' + more + '</a></p>');
}
}
/**
* Load new posts when the link is clicked.
*/
jQuery('#pbd-alp-load-posts a').click(function() {
// Are there more posts to load?
if(pageNum <= max) {
// Show that we're working.
jQuery(this).text(loading);
jQuery('.pbd-alp-placeholder-'+ pageNum).load(nextLink + ' #content ul.listing-videos li',
function() {
//jQuery('.pbd-alp-placeholder-'+ pageNum).children('li').unwrap();
console.log(pageNum);
jQuery(this).children().hide();
$newContent = jQuery(this).children().unwrap();
$newContent.fadeIn('fast');
// Update page number and nextLink.
pageNum++;
nextLink = nextLink.replace(/\/page\/[0-9]?/, '/page/'+ pageNum);
**// Add a new placeholder, for when user clicks again.
jQuery('#content ul.listing-videos').append('<li class="more-posts pbd-alp-placeholder-'+ pageNum +'"></li>');**
// Update the button message.
if(pageNum <= max) {
jQuery('#pbd-alp-load-posts a').text('Vezi mai multe');
} else {
jQuery('#pbd-alp-load-posts a').remove();
}
}
);
} else {
jQuery('#pbd-alp-load-posts a').append('.');
}
return false;
});
});发布于 2014-11-05 17:58:04
对于wordpress中的ajax分页,你可以使用像https://wordpress.org/plugins/wp-pagenavi/这样的插件。
或
<div id="content">
<?php
$new_query = new WP_Query();
$new_query->query('post_type=post&showposts=1'.'&paged='.$paged);
?>
<?php while ($new_query->have_posts()) : $new_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<div id="pagination">
<?php next_posts_link('« Older Entries', $new_query->max_num_pages) ?>
<?php previous_posts_link('Newer Entries »') ?>
</div>
</div><!-- #content -->
<script>
jQuery(function($) {
$('#content').on('click', '#pagination a', function(e){
e.preventDefault();
var link = $(this).attr('href');
$('#content').fadeOut(500, function(){
$(this).load(link + ' #content', function() {
$(this).fadeIn(500);
});
});
});
});
</script>发布于 2016-02-03 02:13:44
我也有同样的问题。如果仍在发生,请替换:
nextLink = nextLink.replace(/\/page\/[0-9]?/, '/page/'+ pageNum);至
nextLink = nextLink.replace(/\/page\/[0-9]*/, '/page/'+ pageNum);在错误的正则表达式0-9中出现问题?只匹配从1到9的单个数字。从10开始只需要1。而不是0-9*匹配从0到无穷大。所以,它在9之后中断(从0到9),因为下一个10,它只使用了1。
https://stackoverflow.com/questions/26746473
复制相似问题