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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:30:48+00:00 2026-05-27T08:30:48+00:00

In the primary application on which I have been working, and with which Stack

  • 0

In the primary application on which I have been working, and with which Stack Overflow gurus have been lifesavers, I decided to avoid some of the asynchronous complications I’ve seen, by splitting the SortArray branch of my main routine off into its own function. Testing that shows perfect results just before the function returns those results.

The way this saves me some processing is that I can sort the array before I send it into the main processing function. That way, all arrays are treated identically throughout the ProcessArray function.

In the code example below, I show the current structure, which is my interpretation of advice given (most recently by jfriend00). I make two $.getJSON calls, the second within the success clause of the first, and just before I end that first getJSON call (at which point I have tested and validated the arrays created during the processing not shown here), I call SortArray on one of the arrays, then pass it to the routine that sends the result into ProcessArray.

Despite the success of the SortArray code within itself, the array that enters ProcessArray by this means is noted as “undefined.” If this isn’t more problems with asynchronous processing, I presume it is a problem with array reference. But I don’t know how to solve it.

function buildTree(centralID) {
  $(document).ready(function(){
    $.getJSON('MurakiMaida.json', function(data) {
        $.each(data.person, function(i, xdata) {
        ...create a small set of arrays
        }); //end of first $.each() routine
        $.getJSON('MurakiMaida.json', function(data) {
            $.each(data.person, function(i, xdata) {
            ...use an array just created to create another
            }); //end of second each()
        }); //end of second getJSON
        $("#spchildren").html(ProcessArray(SortArray(childIDs, true), centralID, false));
    }); //end of first getJSON
}); //document.ready
}
  • 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-27T08:30:49+00:00Added an answer on May 27, 2026 at 8:30 am

    If I’m understanding your code correctly (a big if), it’s a problem with asynch processing. Your second Ajax call’s results func is creating the “child” array, right?

    But the Ajax call’s results func isn’t called until later. You’re calling the ProcessArray function right away.

    added
    Maybe this will help:

    Your code (if I understand it right) is the exact same as the following except that I’m naming the functions rather than defining them inline:

    var async_function_1 = function(data) {
       $.each(data.person, function(i, xdata) {
       ...create a small set of arrays
       }); //end of first $.each() routine
    
       $.getJSON('MurakiMaida.json', async_function_2);
    
       $("#spchildren").html(ProcessArray(SortArray(childIDs, true), centralID, false));
       // See the problem? You are calling ProcessArray before async_function_2
       // has a chance to run. 
    } 
    
    var async_function_2 = function(data) {
       $.each(data.person, function(i, xdata) {
       ...use an array just created to create another
       }); //end of second each()
    };
    
    function buildTree(centralID) {
        $(document).ready(function(){
            $.getJSON('MurakiMaida.json', async_function_1);
    }); //document.ready
    }
    

    Fix Move the ProcessArray code into the end of the second async function definition as follows:

    # Same as above except
    
    var async_function_1 = function(data) {
       $.each(data.person, function(i, xdata) {
       ...create a small set of arrays
       }); //end of first $.each() routine
    
       $.getJSON('MurakiMaida.json', async_function_2);
    } 
    
    var async_function_2 = function(data) {
       $.each(data.person, function(i, xdata) {
       ...use an array just created to create another
       }); //end of second each()
       $("#spchildren").html(ProcessArray(SortArray(childIDs, true), centralID, false));
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The root problem: I have an application which has been running for several months
I have an (ASP.NET 3.5) intranet application which has been designed to use forms
I have two web applications (A) and (B). (A) is my primary web application.
I have an application that has a primary layout of portrait (it is fixed
OK so I've been tasked with upgrading an application which involves updating schema in
I have made a sample application in which I am able to implement help
In my application I have two queries which will be quite frequently used. The
I have been tasked with doing some planning and research for a home grown
I have a .NET application which allows users to access various databases by providing
I have a small application which consists of a DAL, BLL and the Application

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.