Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8251279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:11:00+00:00 2026-06-08T00:11:00+00:00

I have a JS Function which is called in document.ready. The intent is as

  • 0

I have a JS Function which is called in document.ready. The intent is as it scrolls to the bottom window, it’ll load more from the JSON API.

The API has the parameter offset and limit. Offset controls which subset of results you are seeing. For ex. 20-40 would be offset=20 and limit controls how many you can view at once.

I thought I would approach this with a recursive function which calls itself each time the user goes to the bottom of the window, with window.scroll. Once they go to the bottom, it’ll increment the offset by 20 each time, then run the function again.

Problem: I can’t seem to get it to increment the variable by 20 to make this work. Thoughts?

function getData(offset) {
var jsonCallback = "&jsoncallback=?";
//var offset = 20;
//var offset += 20;
var limit = 20;

var characterURL = "http://api.example.com/character&byId=" + characterID + "&offset=" + offset + "&limit=" + limit;    

$.getJSON(characterURL + jsonCallback, function(data) {
    for (i=0; i < (data.data.results).length; i++) {

        var $characterUl = $("<ul>");
        $characterUl.appendTo("#characterComics");
        $("<li>").text(data.data.results[i].title).appendTo($characterUl);  
        $("<li>").text(data.data.results[i].id).appendTo($characterUl);  
        $("<li>").text(data.data.results[i].release_date).appendTo($characterUl);  
        if (data.data.results[i].release_date > 0) {
            $characterLi.text(data.data.results[i].issue_number).appendTo($characterUl);      
        }  
    }

    $(window).scroll(function() {
        if($(window).scrollTop() + $(window).height() > $(document).height() - 10) {
            while ((data.data.results).length === offset || (data.data.results).length > offset) {
                offset = offset+20;
                $("<div>").text(offset).appendTo("body");
                getComics(offset);
            }
        }
    });
   });
}

$(document).ready(function() {    
var $characterComics = $("<div>", {id : "characterComics"});
$characterComics.appendTo("body");
getData(0);
}); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:11:01+00:00Added an answer on June 8, 2026 at 12:11 am

    UPDATED
    Read this more as a pseudo-code

    function getData(offset) {
        var jsonCallback = "&jsoncallback=?",
        characterURL = "http://api.example.com/character&byId=" + characterID + "&offset=" + offset + "&limit=" + limit;    
    
        $.getJSON(characterURL + jsonCallback, function(data) {
            for (i=0; i < (data.data.results).length; i++) {
                var $listItem = $("<li>");
                listItem.append("<span>"+data.data.results[i].title+"</span>");
                listItem.append("<span>"+data.data.results[i].id+"</span>");
                listItem.append("<span>"+data.data.results[i].release_date+"</span>"); 
                if (data.data.results[i].release_date > 0) {
                    listItem.append("<span>"+data.data.results[i].issue_number+"</span>");   
                }
                listItem.appendTo($characterUl);
                itemsLoaded++;
            }
       });
    }
    
    $(document).ready(function() {
        var $characterComics = $("<div>", {id : "characterComics"}),
            $characterUl = $("<ul>"),
            offset = 0,
            itemsLoaded = 0;
            limit = 20;
        $characterComics.appendTo("body");
        $characterUl.appendTo($characterComics);
    
        $(window).scroll(function() {
            if($(window).scrollTop() + $(window).height() > $(document).height() - 10) {
                if ("check here if you reached your offsets") {
                    offset = offset+20;
                    getData(offset);
                }
            }
        });
       // get your first set of data
       getData(0);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have some code like this which is called on $(document).ready() $(.someClass).click(function(){ //do
I have a function which calculates distance from database records. This function is called
I have a Function in CFC file, which will be called from .cfm file
I have a jquery function that is called on $(document).ready that modifies the css
I'd like to have a javascript function called on page load and unload which
hi i have function which is called by tinker listbox so i cannot return
I am using jQuery(Latest release) and have a function called calculate() which gets called
I have a function, which is called sometimes with regular, sometimes dynamic arrays. If
I have a function: def create(sender, **kw): [...] Which should be called when the
I have a function called PreProcessSource, which allocates a boost::wave::context and does some preprocessing;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.