d3.csv and XMLHttpRequest cannot load

2,536 views
Skip to first unread message

Gabriel

unread,
Sep 27, 2016, 5:27:05 PM9/27/16
to d3-js
Hello all,

I'm trying to load the tiny cities.csv test file 

city; population
new york; 1000
brussels; 508
venice; 609
leuven; 905
helsinki; 717

inside my d3 program as 

  d3.csv("cities.csv", function(data) {

                  console.log(data[0]);

                  });


This does not seem to work, and I get the error Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.


Now, I'm absolutely not familiar with HTTP and servers and have looked a bit around, but am quite confused about it. Should I make a local server (or something like that) using Python's -m SimpleHTTPServer, or is there another way around? Why does this problem arise?


Thanks for all the input!

Gabriel

Danne Woo

unread,
Sep 27, 2016, 8:35:09 PM9/27/16
to d3...@googlegroups.com

Hi Gabriel,

This issue pops up when you try and load the website locally on your machine. To avoid this error you either need to run a localhost on your machine or upload it to a web server. If you are running this on a Mac you can run a simple local web server by cd -ing into the root folder in Terminal and running “python -m SimpleHTTPServer”. Heres a tutorial: http://lifehacker.com/start-a-simple-web-server-from-any-directory-on-your-ma-496425450 <http://lifehacker.com/start-a-simple-web-server-from-any-directory-on-your-ma-496425450>.

Good luck, cheers,


Danne Woo


--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gabriel

unread,
Sep 27, 2016, 11:09:24 PM9/27/16
to d3-js
Hello Danne,

Thanks for your response. One more question: once this localhost is run (which I could do with success), should I put a file in it? Or should I just let it open without doing anything with it?

Thanks for the clarification!

Best wishes,
Gabriel

Danne Woo

unread,
Sep 27, 2016, 11:56:13 PM9/27/16
to d3...@googlegroups.com
Yes all your files (HTML, CSS, JavaScript, and Data Files) should be in the folder you are running the local server on. You should probably have an index.html file in there, if you go to the browser and go to http://localhost:8000 (8000 might be different for you, its whatever port you are running this server on) this will load the index.html file in the browser. If you have a html file with a different name you need to reference that filename i.e. http://localhost:8000/d3chart.html.

Good luck, cheers,

Danne

Gabriel

Reply all
Reply to author
Forward
0 new messages