【问题标题】:How do I load more posts using a button如何使用按钮加载更多帖子
【发布时间】:2013-09-24 13:24:33
【问题描述】:

我有以下代码来加载前 10 篇博文,并想看看如何在列表末尾添加“更多...”文本链接以加载更多博文:

$(document).ready(function(){
    url = 'http://hopexxx.com/category/daily-devotion/feed/';
    $.ajax({
        type: "GET",
        url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
        dataType: 'json',
        error: function(){
            alert('Unable to load feed, Incorrect path or invalid feed');
        },
        success: function(data){
            var postlist = data.responseData.feed.entries;
            var html = '<ul data-role="listview" data-filter="true">';
            for (var i = 0; i < 10; i++) {
                var entry = postlist[i];
                html += '<li>';
                html += '<a href="#">';
                html += '<div class="entry">' + entry.title + '</div>';
                html += '<div class="entry">' + entry.author + '</div>';
                html += '<div class="entry">' + entry.publishedDate + '</div>';
                html += '<div class="entry">' + entry.contentSnippet + '</div>';
                html += '</a>';
                html += '</li>';
            }
            html += '</ul>';
            $("#postlist").append(html);
           $("#postlist ul[data-role=listview]").listview();

        }});
    });

【问题讨论】:

    标签: javascript jquery ajax wordpress dom


    【解决方案1】:

    谷歌提要 API 没有跳过元素的选项,它只是一个提要,因此它会加载所有元素(因为您已经定义了 num=... 您已经知道可以加载超过 4 个元素(这是默认值)。

    要执行您想要的操作,您必须在单击按钮时调用相同的请求,然后执行一些逻辑来比较新结果是否包含页面上未显示的元素。如果是这样,只需附加它们...

    【讨论】:

    • 他为什么每次都要求发帖?为什么不在开始时将其存储在某个全局变量中,然后做他需要的任何事情。
    • 阅读问题,他想检索 10 并点击一个按钮,他想加载更多...
    猜你喜欢
    • 1970-01-01
    • 2017-12-21
    • 2015-10-13
    • 2016-07-16
    • 2023-03-23
    • 1970-01-01
    • 2016-06-08
    • 2018-03-26
    • 2018-08-02
    相关资源
    最近更新 更多