简体   繁体   English

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

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

I need to make an ajax pagination of a Behance Design portfolio using the Behance API. 我需要使用Behance API对Behance Design产品组合进行ajax分页。

I found out that in order to display all the projects from a design Behance portfolio using the API key, I need to paginate changing the query get at the end of the JSON url. 我发现,为了使用API​​密钥显示设计Behance产品组合中的所有项目,我需要对JSON URL末尾的查询get进行分页更改。

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

So the point is: how can I know when I get the end, when I don't have to paginate anymore ? 因此,重点是:如何知道何时结束,何时不再需要分页?

Apparently the number of pages is not available and the total number of project neither, I can only go for "page=1, page=2, page=3" etc... but no idea which one is gonna be the last one. 显然页数不可用,项目总数也不可用,我只能输入“ page = 1,page = 2,page = 3”等……但不知道哪一个将成为最后一个。 And of course, if I try to make a call of an inexistent page, I get an error. 当然,如果我尝试调用不存在的页面,则会收到错误消息。

Some idea? 有想法吗

I solved it. 我解决了

Basically every AJAX call made to load the results is followed by another one (that would theoretically be the next one) just to check if there are other results to show. 基本上,每次进行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