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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:43:00+00:00 2026-05-29T23:43:00+00:00

I’m using the JIT and making a spacetree, but the data the server returns

  • 0

I’m using the JIT and making a spacetree, but the data the server returns isn’t in the proper format, so I figured it would be easiest to just build a string that IS the right format and then parse that with eval (which works fine). The problem now comes in that I need to use another string of JSON that isn’t in the right format to add children nodes to the space tree, and I now have no idea what I’m doing. Here’s my code:

function grabdata(empid, fname, lname){
    var json = ''; 
    jQuery.getJSON('../../Mobile_ReportingChain.cfm?Empid='+empid, function(data) {
        console.log(data);
        for(var i=data.DATA.length-1; i>=0; i--){
            json = json + 'id: "' + data.DATA[i][3] + '",name: "' + data.DATA[i][0] + ' ' + data.DATA[i][1] + '",data: {},children: [{';
        }
        json = json + 'id: "' + empid + '",name: "' + fname + ' ' + lname + '",data: {},children: [';
        alert("JSON 1: " + json);
        jQuery.getJSON('../../Mobile_Subordinate.cfm?Empid='+empid, function(data2) { 
            console.log(data2);
            for(var i=0; i<data2.DATA.length; i++){
                json = json + '{id: "' + data2.DATA[i][4] + '",name: "' + data2.DATA[i][0] + ' ' + data2.DATA[i][1] + '",data: {},children: []},';
            }
            alert("JSON 2: " + json);
        });
        json = json + ']';
        for(var i=data.DATA.length; i>0; i--){
            json = json + '}]';
        }
        alert("JSON 3: " + json);
    });
}

Here’s what I’m getting from the alerts, and what my goal is:

JSON 1: id: "000-25-9687",name: "NAME1          LNAME1                  ",data: {},children: [{id: "000-91-3619",name: "FNAME2            LNAME2                  ",data: {},children: [{id: "000-01-2302",name: "FNAME3            LNAME3                    ",data: {},children: [{id: "000-14-7189",name: "FNAME4           LNAME4                  ",data: {},children: [{id: "000-62-7276",name: "FNAME5 LNAME5",data: {},children: [

JSON 2: id: "000-25-9687",name: "NAME1          LNAME1                  ",data: {},children: [{id: "000-91-3619",name: "FNAME2            LNAME2                  ",data: {},children: [{id: "000-01-2302",name: "FNAME3            LNAME3                    ",data: {},children: [{id: "000-14-7189",name: "FNAME4           LNAME4                  ",data: {},children: [{id: "000-62-7276",name: "FNAME5 LNAME5",data: {},children: []}]}]}]}]{id: "000-21-6506     ",name: "CHILD1          CHILDLNAME1                    ",data: {},children: []},{id: "000-17-7989     ",name: "CHILD2          CHILDLNAME2                   ",data: {},children: []},{id: "000-23-6712     ",name: "CHILD3        CHILDLNAME3              ",data: {},children: []},

JSON 3: id: "000-25-9687",name: "NAME1          LNAME1                  ",data: {},children: [{id: "000-91-3619",name: "FNAME2            LNAME2                  ",data: {},children: [{id: "000-01-2302",name: "FNAME3            LNAME3                    ",data: {},children: [{id: "000-14-7189",name: "FNAME4           LNAME4                  ",data: {},children: [{id: "000-62-7276",name: "FNAME5 LNAME5",data: {},children: []}]}]}]}]

JSON 4: id: "000-25-9687",name: "NAME1          LNAME1                  ",data: {},children: [{id: "000-91-3619",name: "FNAME2            LNAME2                  ",data: {},children: [{id: "000-01-2302",name: "FNAME3            LNAME3                    ",data: {},children: [{id: "000-14-7189",name: "FNAME4           LNAME4                  ",data: {},children: [{id: "000-62-7276",name: "FNAME5 LNAME5",data: {},children: [{id: "000-21-6506     ",name: "CHILD1          CHILDLNAME1                    ",data: {},children: []},{id: "000-17-7989     ",name: "CHILD2          CHILDLNAME2                   ",data: {},children: []},{id: "000-23-6712     ",name: "CHILD3        CHILDLNAME3              ",data: {},children: []},]}]}]}]}]

Obviously it’s moving on past and doing what makes the JSON3 alert before it has time to grab and build the JSON2 alert. How do I make it stop and wait for that getJSON call to finish and the success function to finish before it goes on?

  • 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-29T23:43:01+00:00Added an answer on May 29, 2026 at 11:43 pm

    As a general rule, if you’re making an asynchronous call (like jQuery.getJSON), anything in the script after that call is going to be executed before the asynchronous call completes.

    If you want to keep things crsytal clear, you can write your code like this:

    function grabdata(empid, fname, lname){
        jQuery.getJSON('../../Mobile_ReportingChain.cfm?Empid='+empid, function(data) {
            jQuery.getJSON('../../Mobile_Subordinate.cfm?Empid='+empid, function(data2) { 
    
                // DO ALL YOUR STUFF WITH data AND data2 HERE
    
            });
        });
    }
    

    It’s not optimal, but it’s clear that both AJAX calls must complete before the code in the innermost block will execute.


    If you’re looking as more advanced handling of multiple concurrent ajax requests, you can create a promise that executes on the completion of two asynce requests with jQuery.when().

    Here’s an example:

    $.when(
        $.getJSON('../../Mobile_ReportingChain.cfm?Empid='+empid),
        $.getJSON('../../Mobile_Subordinate.cfm?Empid='+empid)
    ).done(function (data, data2){
    
                // DO ALL YOUR STUFF WITH data AND data2 HERE
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.