【问题标题】:Ajax pagination, knowing the last page - Behance API - jQueryAjax 分页,知道最后一页 - Behance API - jQuery
【发布时间】:2017-06-10 15:21:45
【问题描述】:

我需要使用 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”等...但不知道哪个是最后一个。当然,如果我尝试调用一个不存在的页面,我会收到错误消息。

有什么想法吗?

【问题讨论】:

    标签: jquery ajax pagination behance-api


    【解决方案1】:

    我解决了。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-18
      • 2013-10-31
      • 1970-01-01
      相关资源
      最近更新 更多