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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:38:53+00:00 2026-06-18T11:38:53+00:00

I have this code below, and I want to return the data in the

  • 0

I have this code below, and I want to return the data in the success function of the ajax call. Of course, if I do async:false and return it directly I get it but I don’t want to do that.

If I just run it like it is now, information variable is undefined (if I do async:false, it gets the information, so it isn’t the contents of the data that is the issue).

I just don’t understand why it isn’t working, I googled callback functions and it appears that I am doing it right…

function PUT_updateSystem(id) {
    var system= {};
    system= getSystemInformation(name, function(data){
                                var system = data;
                                return system;});

    var information = system.info;

}
// Returns system information
function getSystemInformation(name,callback){
    $.ajax({
        type:"GET",
        url: getUrl(),
        cache: false,
        dataType: "json",
        success: function(data){
            callback(data);
        }
    });
}

EDIT:
Changed my code to what I currently have

I am generating a jsTree with this data, and to create the json data for that tree I am doing the above but putting the information variable into an object and iterating over it to create nodes. The issue isn’t with the tree, so I won’t include that here. I can even take that logic out to test.

So what is happening,

  1. Page starts loading
  2. I perform the above
  3. Information gets put into a javascript object
  4. I iterate over the javascript object.
  5. I receive an error “Cannot read property ‘length’ of undefined”
  6. As I’m debugging, I see that it skips over system.done. This makes sense because it may not be done.

Is there a way to wait for it to be done?

EDIT:
Providing more information

// IN A FILE CALLED loadinfo.js

// Returns system information promise
function getSystemInformation(){
    return $.ajax({
        type:"GET",
        url: getUrl(), // url is defined somewhere else
        cache: false,
        dataType: "json"
    });
}

// IN A FILE CALLED tree.js
// I have other variables from loadinfo.js that are here so they can communicate fine

    $.when(getSystemInformation(), $.Deferred(function(deferred) {
        $(deferred.resolve);
    })).done(function(data) {
        mapCache["system"] = data;
        console.log("defer DONE!!");

$.each(mapCache["system"], function(index, system) {
            var children = doDisplayChildNodes(system.name);
            ...
                    ...
});

What I’m doing in this $.each is just grabbing data from mapCache[“system”] and creating a “jstree” node. I do a child function to do the same thing, because I have child nodes associated with each system. All of this logic worked because it work working fine when I had the ajax call as “async:false” — so I won’t post that.

I receive the Cannot read property ‘length’ of undefined during the $.each. Which is strange because I have a “Watch” set on mapCache and after everything is loaded, mapCache is filled with the correct values. I am using Google Chrome debugging.

  • 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-18T11:38:55+00:00Added an answer on June 18, 2026 at 11:38 am

    You used a callback, however you still used it with synchronous logic rather than asynchronous. Try doing it this way:

    function PUT_updateSystem(id) {
        var system = getSystemInformation(name);
        system.done(function(data){
            var information = data.info;
            // do stuff with `information` here, not elsewhere.
        });
    }
    // Returns system information promise
    function getSystemInformation(name){
        return $.ajax({
            type:"GET",
            url: getUrl(),
            cache: false,
            dataType: "json"
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this snippet of code below. I want to pass the value of
I have the code below and I want to loop this every 5 seconds.
I have ajax code like this which is passing form data into createfinalinvoice.php. serial_number
I have the below jQuery code: $(document).ready(function () { $('#ajaxButton').click(function () { $.ajax({ url:
I have this code below. I need to use a class id instead of
I have this code below. As you can see I am passing two variables
I have this code below: $insert = array(); for ($i = 1, $n =
I have this javascript code below that uses jquery, it is suppoed to be
I have this below code and it work fine header (content-type: text/xml); $xml =
I have this kind of code below, how can I bind the visibility of

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.