I am trying to retrieve some data from neo4j for my web app. I have my code structured in the following manner:
When I click the button to retrieve the data, call
var childNodes = getAllChildNodes(uuid, ""); //uuid: node specific id in neo4j, second param not important
//do something with childNodes 
....
In getAllChildNodes(),
function getAllChildNodes(uuid, filter) {
    /*
    prepare json data to send
    */
    
    var resultNodes = {}
    var successFunction = function(data) {
        //store data in resultNodes ...
        //do something with the data ...
    }
    var failFunction = function(xhr, status, error) {
        //if query fails
    };
    //call to API function
    try {
        getChildrenAPI(jsonData, successFunction, failFunction)
    } catch (err) { console.log(err) }
    return resultNodes
}
In getChildrenAPI
function getChildrenAPI(jsonData, doneFunction, failFunction) {
                    var request = $.ajax({
                    method : 'POST',
                    url: myurl,
                    data : JSON.stringify(jsonData),
                    dataType : 'json',
                    contentType : 'application/json',
                    cache : false,
                    async : true,
                });
                request.done(function (data) {
                    doneFunction(data)
                })
                request.fail(function (xhr, status, error) {
                    failFunction( xhr, status, error );
                });
}
The problem is that my childNodes var does not get populated. When I inspected further, in my getAllChildNodes() function, resultNodes is returned before the query data is stored in successFunction(). I thought this would be an async issue, so I made sure to check that the AJAX call had its async property set to true, but that didn't solve it. So I tried using async await on my getAllChildNodes(), but that didn't work either. So my question is, what am I doing wrong here? I'm still new to the idea of async so this was the best I can do. If someone can please help me with this I would really appreciate it.
 
     
     
    