1

Hello I have a jquery ajax call that returns json data from an api.

I turned that json into a variable and want to use it in d3.json.

It isnt taking the variable name, I think because its expecting a url instead of a variable name.

Here is the code:

jQuery.ajax({
    type: "GET",
    url: myurl.com,
    success: function(effects)
    {
        var dataArray = effects;

            d3.json(dataArray, function (data) { //error here
                console.log(data);
            });
    }
});

Those of you good with d3, can you help me get the json data into the d3.json function?

Thanks

3
  • 2
    I think there is a slight misconception on what both methods actually do. d3.json() is not just for parsing; it will request the JSON resource and parse it, whereas jQuery.ajax() only requests the resource without parsing it. When using jQuery.ajax() you need to use the native JSON.parse() to parse the JSON string, not d3.json()**! Commented Jul 25, 2017 at 9:17
  • oh! makes sense now, thank you for the explanation Commented Jul 25, 2017 at 16:16
  • d3.json already does the AJAX request for you, so I'd just use that if possible. Commented May 11, 2022 at 2:29

1 Answer 1

1

I think you've got the data from API which you called effects. I suppose that the effects are in json format like "key":"value" paires, you can try var jsonVariable = effects["key"] to get the value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.