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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:30:07+00:00 2026-06-13T07:30:07+00:00

I have a JsTree that gets populated based on the JSON Data that I

  • 0

I have a JsTree that gets populated based on the JSON Data that I receive from an AJAX call. Here is the AJAX call.

function sendQuery(){
    $.ajax({
        context: this,
        url: 'http://localhost:8080/testMain',
        type: 'GET',
        dataType: 'text',
        success: function(data) {
                       // ^^^^ Need for sendQuery() to return DATA 
                },
        error:  function (xhr, ajaxOptions, thrownError){    
                    alert('Error xhr : ' + xhr.status);    
                    alert('Error thrown error: ' + thrownError);    
                }
    }); 
}

I am aware that there is a scope problem here. In JavaScript variables are defined as per the declaring function. I just dont know how to return from sendQuery() which I am then using as the parameter to another function which will parse the JSON, which is the parameter for another to stage for the tree. Kinda frustrated with this piece in the clockwork not working out to be as simple as what I am used to in Java. Thanks so much for the help, and if it works then ill definitely accept. Cheers

EDIT #1 : Ok so based on the answers, I believe if I change my code in this fashion it will allow for data to get out of the .ajax function. There remains the question of how to get it back into the flow of the program.

function sendQuery(){
    $.ajax({
        context: this,
        url: 'http://localhost:8080/testMain',
        type: 'GET',
        dataType: 'text',
        success: getJson,
        error:  function (xhr, ajaxOptions, thrownError){    
            alert('Error xhr : ' + xhr.status);    
            alert('Error thrown error: ' + thrownError);    
        }
    }); 
}

function getJson(data){
    alert("Transmission Success.");
    alert(data);
    var obj = $.parseJSON(data);
    alert("Parsing JSON Success.");
    var apples = obj.apples;
    alert(apples);
    return apples;
}

Ok so now how do I get the APPLES variable into the chain of call which will stage the data for the tree?

I need to feed the APPLES variable to a function which will process the data.

EDIT #2 Using a Callback:

Took me a second to wrap my head around the idea of a callback. Here is what I was able to do with it.

Here is my original tree code, it calls a series of functions to do different things but ultimately get the data in the form which the tree will accept.

$(function () {     
    $("#client_tree").jstree({
        "json_data": {"data": attachTree(stageTreeData(getJson(sendQuery())))}, 
        "plugins" : [ "themes", "json_data", "ui" ]
    }).bind("select_node.jstree", function (e, data) { 
        var msg = data.rslt.obj.attr("id");
        alert(msg);
    });
});

I at the moment am trying to get the data via Ajax, in the sendQuery() method then return from it with data etc…]

I changed it slightly, now I dont call sendQuery(), jQuery calls it.

$(function (){
    $.ajax({
        context: this,
        url: 'http://localhost:8080/testMain',
        type: 'GET',
        dataType: 'text',
        success: loadTree,
        error:  function (xhr, ajaxOptions, thrownError){    
            alert('Error xhr : ' + xhr.status);    
            alert('Error thrown error: ' + thrownError);    
        }
    });
});

Also changed my tree loading code a bit…

function loadTree(data){
    $("#client_tree").jstree({
        "json_data": {"data": attachTree(stageTreeData(getJson(data)))},    
        "plugins" : [ "themes", "json_data", "ui" ]
    }).bind("select_node.jstree", function (e, data) { 
        var msg = data.rslt.obj.attr("id");
        alert(msg);
    });

}

I have no errors, no exceptions and the tree is populated.

Thank you all for helping!

EDIT#3 Fixing some minor stuff:

Moved to Alert() call in jQuery not displaying, called from within a JsTree

  • 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-13T07:30:08+00:00Added an answer on June 13, 2026 at 7:30 am

    You need to consume the data within the AJAX success. Can use another function as this code shows

       function sendQuery(){
            $.ajax({
                context: this,
                url: 'http://localhost:8080/testMain',
                type: 'GET',
                dataType: 'text',
                success: loadTree,
    
                error:  function (xhr, ajaxOptions, thrownError){    
                            alert('Error xhr : ' + xhr.status);    
                            alert('Error thrown error: ' + thrownError);    
                        }
            }); 
        }
    
    
    function loadTree( data){
       /* do something with data returned from ajax*/
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nice jstree that loads data and so on - now I
I am generating jstree from struts2 and JSON from database. From DB I have
I have a JTree populated with some (custom) nodes. I have a class that's
I have a tree(jstree) inside a div, so when a node gets expanded the
using jsTreev pre 1 stable and hotkeys plugin. I have a function that is
I have a Jstree that holds a lot of nodes, some of them have
I have a ASP.NET MVC 4.0 project using JsTree. The JsTree is being populated
I have a strange problem with JSTree and Ajax. I generate my tree via
I have two questions regarding jsTree: I am generating a jsTree using JSON with
I'm trying to have the jstree ONLY return the text for the node that

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.