阿贾克斯分页字preSS分页、阿贾克斯、preSS

2023-09-10 20:23:52 作者:蹲在街角卖回忆

我有一个问题,我的字preSS阿贾克斯分页:

I have an issue with my ajax pagination on wordpress :

$(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);
            });
        });
    });
});

在我的网页的URL是这样的:本地主机/ my_site /页/ X 在分页工作良好,没有的JavaScript 这code的工作很奇怪,当我有这种类型的永久的:本地主机/ my_site /&放大器;分页= X(的X + 1 / X-1和下一首/ $ P $光伏环节的工作,但是当我打电话最后一页什么都没有发生) 现在,我有一个错误,当我CONSOLE.LOG .load的误差()(错误)

The url of my page is like : localhost/my_site/page/x The pagination works well without javascript This code worked strangely when i had this type of permalink: localhost/my_site/?&paged=x (The x+1/x-1 and next/prev links worked but when i called the last page nothing happened) Now i have an error when i console.log the error of .load() ("error")

我怎么能调试吗? (我不是familliar足够使用Ajax:秒)。

How can i debug this? (Im not familliar enough with ajax :s).

你有任何想法,我可以尝试修复它?

Do you have any idea what i can try to fix it?

感谢您的时间

推荐答案

好了,所以我定了!

由于我的网址是正确的,我不得不到服务器的响应头更改为标题(HTTP / 1.1 200 OK); 之前的任何code 我的header.php文件的

As my url was correct i had to change the header of the server's response to header("HTTP/1.1 200 OK"); before any code of my header.php file

我真的不知道我是否需要将其删除它时,我会来督促,或者是否会再拍问题,但现在它的全面工作。希望我能避免别人浪费时间在这:)

I don't really know if i will need to remove it when i will come to prod, or if that will make another issues but, now it's fully working. Hope i could avoid someone else wasting time on this :)