繁体   English   中英

Ajax分页,知道最后一页-Behance API-jQuery

[英]Ajax pagination, knowing the last page - Behance API - jQuery

我需要使用Behance API对Behance Design产品组合进行ajax分页。

我发现,为了使用API​​密钥显示设计Behance产品组合中的所有项目,我需要对JSON URL末尾的查询get进行分页更改。

https://api.behance.net/v2/users/rolfo85/projects?client_id=APIKEY&per_page=25&page = 2

因此,重点是:如何知道何时结束,何时不再需要分页?

显然页数不可用,项目总数也不可用,我只能输入“ page = 1,page = 2,page = 3”等……但不知道哪一个将成为最后一个。 当然,如果我尝试调用不存在的页面,则会收到错误消息。

有想法吗

我解决了

基本上,每次进行AJAX调用以加载结果后,都会进行另一个调用(理论上将是下一个),以检查是否有其他结果要显示。

$.ajax({

        url: urlNext, // it is the url with the next page index
        dataType: 'jsonp',

        success: function(check) {

            if ( check.projects.length > 0 ) {

                // there are other results to load, so do something

            } else {

                // there are NO other results to load, so do something

            }

        },
        error: function(error) {
            console.log('Error: ', error);
        }

    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM