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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:28:07+00:00 2026-06-02T21:28:07+00:00

For a photogalery I load a file (via ajax) which returns an array of

  • 0

For a photogalery I load a file (via ajax) which returns an array of src’s of the images I want to display. They HAVE TO be displayed in the exact order the ajax call returns.

I’m using a for-loop with the .load() function inside it, but that way it’s not synchronised. If I output the value of i inside the .load() function, it doesn’t go 0, 1, 3, 4, etc. but 0, 3, 2, 4, etc.

The simplified version of my code:

$.get('photostack.php', {album_name:album_name} , function(data) {
var items_count = data.length;
for(var i = 0; i < items_count; ++i){
    var item_source = data[i];
    var cnt = 0;
    $('<img />').load(function(){
        var $image = $(this);
        ++cnt;
        console.log(i);
        $ps_container.append($image);
    }).attr('src',item_source).attr('class',i);
}
},'json');

console.log(i) now gives the wrong order. It should be perfectly ascending.

I have tried a lot of things. Delaying every load 100 ms, using an object as variable for cnt/i, etc. but none of them worked.

  • 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-02T21:28:09+00:00Added an answer on June 2, 2026 at 9:28 pm

    Not sure I really get it, but maybe something like this will work:

    $.get('photostack.php', {album_name:album_name} , function(data) {
        for(var i = 0; i < data.length; i++){
            var image = new Image();
                image.src = data[i];
                image.className = i;
                image.style.display = 'none';
            $(image).appendTo($ps_container).load(function() {
                $(this).show();
            });
        }
    },'json');​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create my site and in the page have it so that
I have a photo-galley which i show using fancybox, It works fine. i need
I have the following schema.yml file: Page: actAs: I18n: fields: [name,html,urlShortDesc] columns: name: string
I'm having problems getting my JPanel to display properly. I want to use different
I have a picture gallery and I use fancybox to display pictures, and navigate
I am new to AJAX and have this issue. I am creating a photogallery
So I have a site that requires login to view, which has a photo
How could I query an xml file, like the one below, with C# .NET
Here is what I have so far, I apologize for the length but this
I have the following markup with inline javascript and would like to change it

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.