ICoded
ICoded

Reputation: 341

D3v6 fetch json

I decided to migrate my D3v4 forced graph to d3v6 and it seems that the fetching logic changed. I do not get any node or link displayed. just none. I am pretty sure the fetching is causing the problem, because as soon as I add test json data, directly into the code, its fine.

d3.json("graph.json", function (error, graph) {
if (error) throw error 
})

Firefox is not showing any error and but Chrome complains about "Uncaught (in promise) TypeError: failed to fetch.

enter image description here

The file I am trying to fetch is locally stored in the same root folder where the .js is located.

In case anybody faced a similar problem I would appreciate to share this information.

Upvotes: 0

Views: 49

Answers (1)

Abhinav Kumar
Abhinav Kumar

Reputation: 3036

You need to server the file from a server, directly loading from the file system, browser won't be able to load the file and fetch.

You may use any server and just server the static files or even you can use '200 OK' google chrome extension to serve files.

Fetch API internally look for resources that is getting served, it just can't load file from the file system.

Upvotes: 1

Related Questions