4

I'm trying to get started with d3.js and something isn't right. I have this tag in my <head> section

<script src="https://d3js.org/d3.v5.min.js"></script>

and this code in my javascript file

d3.json('http://localhost:53526/api/foo', function (data) {
    console.log(data);
});

The problem is the call back never happens. No data is ever logged. Here's my javascript console: enter image description here

But I can see the data from my json api in the network tab! enter image description here It has sent a request and the request was successful but yet it doesn't call the callback function.

I've also read many examples of people using d3.request(url).get but whenever I try this I just get the error message

Uncaught TypeError: d3.request is not a function

I'm getting the exact same behavior from both Chrome and Firefox. Have I missed something very basic here? Why doesn't d3 load any data?

Community
  • 1
  • 1
Matthew
  • 4,149
  • 2
  • 26
  • 53
  • 4
    d3.request isn't working because you're using D3 version 5 and d3.request is deprecated. Use d3-fetch instead: https://github.com/d3/d3-fetch – seaotternerd Apr 16 '18 at 22:50
  • 1
    Ok, it looks like my issue is that the specification has changed since most of the tutorials I found were written. Should be `d3.json(uri).then`. I knew it had to be something simple, but I didn't spot the difference in the docs – Matthew Apr 16 '18 at 22:59

0 Answers0