javascript - Ajax分页wordpress

标签 javascript jquery ajax wordpress

我在 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/

相关文章:

javascript - 如何使用javascript删除html标签之间的空白?

Javascript OOP 构造函数使用 ajax 初始化数据 - 在原型(prototype)中不可用

javascript - 为什么我的数据表没有在函数内部使用 $.each 出现?

javascript - 如何使用 Webdriver 在 Facebook 弹出窗口中填写凭据 (javascript)

javascript - 如何使用 fs.readStream 和 fs.writesream 发送和接收视频(.mp4)文件[从客户端到服务器,反之亦然][在 Node Js 中]?

php - 从 AJAX 下拉菜单中保存的数据不正确

javascript - 从前端进行 api 调用

使用 javascript 的 ASP.net 隐藏面板

javascript - 附加 html 上的 PreventDefault( ) 不起作用。为什么?

php - JQuery 预先准备崩溃