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 1027689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:16:31+00:00 2026-05-16T12:16:31+00:00

I am trying to fetch pictures for a gallery using JavaScript, but I experience

  • 0

I am trying to fetch pictures for a gallery using JavaScript, but I experience problems.

$(document).ready(function() {

    var currentPage = 1;
    var totalPics = 2;
    var picPerPage = 1;
    intervalID = window.setInterval(function() {
          console.log(currentPage*picPerPage);
          if (totalPics > (currentPage*picPerPage)) {
        currentPage++;
        fetchNextPage(currentPage);
          } else {
        clearInterval(intervalID);
          }


    }, 2000);


});

For some reason, it will keeping looping. I want it to stop the moment currentPage * picPerPage > totalPics.

i am using firefox 3.6.8 in ubuntu

update

Thank you guys.

i realise that the issue is due to the fetchNextPage() function.

oncei commented it out, the looping issue is resolved.

however, i need the fetchNextPage function to run a ajax function to fetch another set of images.

below is the function

function fetchNextPage(currentPage) {

    newUrl = currentUrl + currentPage;

    $.ajax({
        url: newUrl ,
        success: function(data) {
            // append page 2 themes
            $('#themes-list').append(data);

        }
    });
}

so what should i do so that my infinite gallery can work?

Thank you.

  • 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-05-16T12:16:32+00:00Added an answer on May 16, 2026 at 12:16 pm

    Your code works for me. I put in console.log() instead of the function and did not correct intervalID not properly defined. Is it possible the function alters values?

    var currentPage = 1;
    var totalPics   = 2;
    var picPerPage  = 1;
    
    intervalID = window.setInterval(function() {
    
        console.log("A", currentPage*picPerPage);
    
        if (totalPics > (currentPage*picPerPage)) {
            currentPage++;
            console.log("B", currentPage);
        } else {
            console.log("C All Done");
            clearInterval(intervalID);
        }
    
    }, 2000);
    

    The output I got (Chrome 5.0.375.127 on OSX):

    A 1
    B 2
    A 2
    C All Done
    

    UPDATE: So with your added code I have a few questions and comments:

    function fetchNextPage(currentPage) {
        var newUrl = currentUrl + currentPage; // Added var declaration here. 
        $.ajax({
            url: newUrl ,
            success: function(data) {
                // append page 2 themes
                $('#themes-list').append(data);
            }
        });
    }
    

    So whats missing here is the data that comes back… can you provide an example of what value data is?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fetch Wikipedia pages using LWP::Simple , but they're not coming back.
How come when I echo $p, the variable which Im trying to fetch using
I'm trying to fetch some HTML from various blogs and have noticed that different
I'm trying to fetch the last inserted row Id of a Sqlite DB in
I'm trying to fetch a genealogy tree of animals from my Oracle database. Here's
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to get my css / C# functions to look like this: body {
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to make a make generic select control that I can dynamically add elements
Trying to keep all the presentation stuff in the xhtml on this project and

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.