什么是促进“加载更多”的最佳方式用jQuery分页? [英] What's the best way to facilitate "Load More" pagination with jQuery?

查看:141
本文介绍了什么是促进“加载更多”的最佳方式用jQuery分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在页面上显示搜索结果列表。在最底部我想放置一个加载更多链接,该链接会在页面上的现有链接中附加更多结果,并将加载更多链接的参数更改为下一页,这样如果用户点击它,下一页将附加到这页纸。在结果加载时出现请稍候或出现一些消息也是很好的。

I'm displaying a list of search results on a page. At the very bottom I would like to place a "Load More" link which appends more results to existing ones on the page and changes the "Load more" link's parameters to next page, so that if user clicks it next page will be appended to the page. It would also be nice to have "Please wait" or some message appear while results are loading.

使用jQuery执行此操作最常用和最实用的方法是什么?

What's the most common and practical way of doing this with jQuery?

谢谢!

推荐答案

我使用类似于以下内容的东西。这是我工作解决方案的简化,省去了无关紧要的事情。希望这可以帮助您入门:

I use something similar to the following. It is a simplification of my working solution, leaving out irrelevant bits and pieces. Hope this can help you get started:

function loadMore(pageNo) {
    $("#loading").html('Loading...').show();
    var url = '/foo/';
    $.get(url, {pageNo: pageNo}, function(response) {
        $("#results").append(response);
        $("#loading").hide();
    });
}

$(document).ready(function() {
    var currPage = 1;
    $("a.next").click(function() {
        loadMore(++currPage);
    });
});

<a class="next">More results</a>

这篇关于什么是促进“加载更多”的最佳方式用jQuery分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆