简体   繁体   中英

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.

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.

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. 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({

        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);
        }

    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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