php部分检测x-pjax头 存在即返回页面正文部分
滚动到底部时 发生ajax请求并附上x-pjax头 写入新标签做第二页
var ajaxloading=true;
$(window).scroll(function() {
if (ajaxloading) {
var pagedz = window.location.pathname;
if (pagedz == "/" || pagedz.indexOf('/page/') == 0||pagedz.indexOf('/category/')==0) {
var url = $('.next:last>a').attr('href');
if (url&&url!=document.location.href) {
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
if (parseInt(scrollTop + windowHeight)+2>= scrollHeight) {
ajaxloading=false;
$('.cssload-fond').show();
$.ajax({
url: url,
dataType: 'html',
timeout: 5000,
beforeSend: function(xhr) {
xhr.setRequestHeader('X-PJAX', 'true')
},
success: function(data) {
console.log('ok');
ajaxloading=true;
$('.nextpage:last').html(data);
var state = {
title: document.title,
url: url,
};
window.history.pushState(null, document.title, url);
$('.page-navigator:first').remove();
$('.cssload-fond').hide();
},
error: function(data) {
console.log("eero" + data);
sendmessage('ajax失败');
$('.cssload-fond').hide();
}
})
}
}
};
};
});