0

我需要使用 Behance API 对 Behance Design 作品集进行 ajax 分页。

我发现为了使用 API 密钥显示设计 Behance 组合中的所有项目,我需要在 JSON url 末尾更改查询获取分页。

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

所以关键是:我怎么知道什么时候结束,什么时候不再需要分页?

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

有什么想法?

4

1 回答 1

0

我解决了。

基本上,为加载结果而进行的每个 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);
        }

    });
于 2017-06-12T01:48:09.023 回答