-1

I am following the examples for reading CSV with Promises described in How to load data from a CSV file in D3 v5

but neither suggested solutions are working for me.

d3.csv('./data_files/NYC.csv')
  .then(function(data) {
      console.log(data)
  })
  .catch(function(error){
     console.log('oops ' + error);
  })

produces Error 0. I know it is not an URL problem because when I specify a non-existent file it returns file not found error.

The other solution suggested is

async function doThings() {
  const data = await d3.csv('./data_files/NYC.csv');
  console.log(data)
}

doThings();

which produces "Unhandled Promise Rejection: Error: 0

This seems straightforward but I can't figure it out. What am I doing wrong?

user13484
  • 1
  • 1

1 Answers1

0

OK, it seems to have been a CORS problem. Either though I have disabled Cross-Origin Restrictions in the developer tools in Safari, CORS seems to be the problem. When I ran it on a server, the above code worked fine.

user13484
  • 1
  • 1