0

Is there any way round the CORS error I'm getting?

I am writing a course on d3. I want students to be able to load JSON, CSV and other data to their webpage. They are instructed to open their html pages locally, by right clicking and going Open With > Browser (i.e. no server). I get the CORS error when I load the data as a gist on github and try to load it. I'm also getting the error when I store the file locally in the same folder as the webpage, and serve it that way. The latter one surprises me as the webpage and the data are coming from the same location.

This is fake data given to students for development purposes only. Is there any way to change settings on github for dev files or is there some way of doing this locally?

Thanks Emma

emma
  • 784
  • 2
  • 9
  • 23

2 Answers2

1

The latter one surprises me as the webpage and the data are coming from the same location.

An HTML document attached to an email as an attachment and then double-clicked in your email client will, for most email clients, be opened from your hard disk. This is the same location as every file on your hard disk. It would be very dangerous to allow JS in any downloaded HTML document free reign to read data.

Is there any way to change settings on github for dev files

No

is there some way of doing this locally?

Have them install an HTTP server and serve their HTML and your data files there.


You could also invest in some cheap hosting (an AWS S3 instance is free for the level of use you are likely to be getting) and host your files there with CORS configured.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks for your answer. I think the hosting is probably the way to go. Some of these students barely know how to write html - a server will be too confusing and put them off. – emma Apr 04 '19 at 10:54
1

Opening the webpage with a basic http server will fix the error if the json or csv are stored locally.

You can take a look at python's simple http server and use it from the command line with the following:

cd folder/of/the/web/page
python -m SimpleHTTPServer 8000

Then open the url localhost:8000 in the browser

sebbab
  • 847
  • 8
  • 13