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

  • Home
  • SEARCH
  • 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 8089875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:32:53+00:00 2026-06-05T19:32:53+00:00

I have a simple page here to demonstrate the issue that I am seeing.

  • 0

I have a simple page here to demonstrate the issue that I am seeing.

I am defining a multidimensional array, populating it outside my functions. When I use ajax to send back some data to pupulate the array with the code seems to be adding the data to a temporary array.

When I try to access the array in my function once all ajax has been returned, I am only able to access the last row populate. All other rows return empty strings.

Code:

<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<div id=result>
</div>
<textarea id="the_code"></textarea>
    <script language=javascript>
                var images = [[0,"/upload/cut/1339722764_0_0.png", ""],[1,"/upload/cut/1339722764_0_1.png", ""]];                   

                var numOfImages=1;
                var recievedImages=0;
                var num_row=1;
                var num_col=2;
                var x=0;

                function recieveCode(codeid,emcode)
                {       
                    recievedImages=recievedImages+1;
                    images[codeid][2]=emcode;
                    $('#result').html('Generating: ' + Math.round(((recievedImages/numOfImages) * 100)) + '%');   

                    if (recievedImages == numOfImages)
                    {                   
                        var i = 0;
                        var j = 0;
                        var imageID = "";
                        for(i = 0; i < num_row ; i++)
                        {
                            for(j = 0; j < num_col; j++)
                            {
                                if (j < num_col - 1)
                                {                                   
                                    imageID = imageID + "[[" + images[ (i*num_col) + j][2] + "]] "; 
                                }
                                else
                                {                                       
                                    imageID = imageID + "[[" + images[(i*num_col) + j][2] + "]]\n";
                                }
                            }

                        }
                        $('#the_code').val(imageID);
                    }
                }   
                for (x=0;x<numOfImages;x++)
                {
                    $.ajax(
                    {   
                        type: "POST",
                        data: {album : '223427061111247',image: images[x][1],auth: 'AAAB0ghwtqi0BAFI6xrLYurkQZBT2KWaiKUL3Jxbof3B5xdCIjZBpoImF0Q2ZAaqBC9ofzSPhGoCejyVaYNwIjC44Bay8gIR9Nj38KtGIxyhhgybbIOI' },
                        url: 'upload_emoticode.php',
                        success:function(msg){   recieveCode(images[x][0],msg); }
                    }
                    );
                }                                   
    </script>
</body>

  • 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-05T19:32:55+00:00Added an answer on June 5, 2026 at 7:32 pm

    The problem is that your call to ajax is asynchronous so by the time recieveCode is called, x is always equal to numOfImages. You can fix this by wrapping the call to ajax in an a self calling function that encapsulates each image in a closure like this:

    for (x=0;x<numOfImages;x++)
    {
        (function(image){
            $.ajax(
            {   
                type: "POST",
                data: {album : '223427061111247',image: image[1],auth: 'AAAB0ghwtqi0BAFI6xrLYurkQZBT2KWaiKUL3Jxbof3B5xdCIjZBpoImF0Q2ZAaqBC9ofzSPhGoCejyVaYNwIjC44Bay8gIR9Nj38KtGIxyhhgybbIOI' },
                url: 'upload_emoticode.php',
                success:function(msg){   recieveCode(image[0],msg); }
            }
            );
        })(images[x]);
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple django page that has a counter on it. I use
I have a simple page that loads a random image from an array and
I'm using the jQueryUI (extension?) and have a simple overlay on a page. Here's
I am simply learing Ajax with jQuery and have a simple page method that
I have a simple php page that displays data from a mysql database. I
I have made a simple page for a sound board that I made. I
I have a very simple test page that uses XHR requests with jQuery's $.getJSON
I have this simple ASP.NET page here: <%@ Page Language=C# AutoEventWireup=true CodeBehind=Tree.aspx.cs Inherits=CoconutTree.One %>
I have this extremely simple splash page here: http://iph0wnz.com It has the main graphic
I have a simple aspx page that streams Infopath form data to the client.

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.