我在 wordpress 上的 ajax 分页遇到问题:
$(function($) {
// When i click on pagination link
$('.last-news').on('click', '.pagination a', function(e){
// I remove the default behavior
e.preventDefault();
// Then i add a smoothscroll to the top
var scrollPosition = $(window).scrollTop(),
$content = $('.last-news .content');
$('html, body').stop().animate({
scrollTop:$("#last-news").offset().top
}, 400);
// There is the ajax code where i get the content of my link
var link = $(this).attr('href');
// I fadeOut the content before i fadeIn the new one
$content.fadeOut(200, function(){
// I call the content of my link
$content.load(link + '.last-news .content', function() {
$content.fadeIn(200);
// I change the url without refreshing the page
history.pushState(null, null, link);
});
});
});
});
- 我的页面网址如下:localhost/my_site/page/x
- 分页无需 JavaScript 即可正常运行
- 当我有这种类型的永久链接时,这段代码工作得很奇怪:localhost/my_site/?&paged=x(x+1/x-1和下一个/上一个链接有效,但当我调用最后一页时什么也没有发生)<
- 现在当我 console.log .load() 的错误(“错误”)时出现错误
我该如何调试这个? (我对 ajax 还不够熟悉:s)。
你知道我可以尝试解决什么问题吗?
感谢您的宝贵时间
最佳答案
好的,我修好了!
由于我的网址正确,我必须在 header 的任何代码之前将服务器响应的 header 更改为 header("HTTP/1.1 200 OK");
.php 文件
我真的不知道当我进入产品时是否需要删除它,或者这是否会产生另一个问题,但是现在它已经完全正常工作了。希望我可以避免其他人在这方面浪费时间:)
关于javascript - Ajax分页wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28644523/