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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:19:34+00:00 2026-06-12T04:19:34+00:00

As a JQUERY/d3-noob, it seems I cannot figure out how to make this work:

  • 0

As a JQUERY/d3-noob, it seems I cannot figure out how to make this work:

  supdog = d3.json(dataPath, function(jsondata){
    return jsondata;
  })
  console.log(supdog);

Thanks in advance.

  • 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-12T04:19:35+00:00Added an answer on June 12, 2026 at 4:19 am

    Besides the fact that your problem description is very terse, the problem seems to be your assumptions about what is returning what.

    The function d3.json() is an asynchronous function that directly returns (with an undefined value I assume). Only when the data is received from the backend, the callback function you passed to it will be called. Obviously the context is different here and the return value of your callback will not automatically become the return value of d3.json (as this one has returned “long” before already).

    What you want to do is probably something like:

        var jsondata;
        d3.json(dataPath, function(dataFromServer) {
          jsondata = dataFromServer;
        }
        console.log(jsondata);
    

    Update 1:
    Obviously, the above example is still not fully correct. The call to console.log() is made directly after the d3.json() returned. Thus, the server might not have sent the reply fully yet. Therefore, you can only access data when the callback is returned. Fixed example:

        var jsondata;
    
        function doSomethingWithData() {
          console.log(jsondata);
        }
    
        d3.json(dataPath, function(dataFromServer) {
          jsondata = dataFromServer;
          doSomethingWithData();
        })
    

    For a (somewhat stupid, but) working example see: http://jsfiddle.net/GhpBt/10/

    Update 2:
    The above example demonstrates in which order the code is executed but does not really deserve a price for most beautiful code. I myself would not use this “global” variable and simplify the above example to:

        function doSomethingWithData(jsondata) {
          console.log(jsondata);
        }
    
        d3.json(dataPath, doSomethingWithData);
    

    Note how doSomethingWithData is directly passed to d3.json in stead of calling it separately in an anonymous inner function.

    Note: This is not a particular problem of d3.js. Basically, all javascript functions that are asynchronous are likely to behave in a similar way. If they return something, it will not be the return value of the passed callback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Jquery did not carry out!!!I don't know why $(.other-edithion).click(function(){ var city = $(this).closest('#city'); if
Just starting out with jQuery and this problem seems to be impossible to me.
I'm a noob in jQuery and have stuck at this. I have the following
Greetings from some noob trying to learn JQuery, I am attempting to make it
I feel noob asking this question but it seems that I cant find the
Im a jquery noob. I needed a script that would swap out images or
Playing around with jQuery a bit (sorry, complete noob) I was wondering why this
I've been spending the last 90 minutes or so trying to figure this out.
This seems like it should be a simple task, but I'm a noob as
I'm trying to make a tracking system and am a bit of jquery noob.

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.