D3.js - load csv file from chrome
Asked Answered
G

4

6

I 've got a webProject with dc.js (d3.js+crossfilter.js) and ndx.csv file. When i run project into chrome from visual studio, everythings is Ok. Now after build project and copy in other computers, Run that.
The problem is here. When i try to run webProject [html file] in other computers with Chrome, this browser has error "XMLHttpRequest cannot load file:///C:/Users/9901/Desktop/WebSite1/ndx.csv. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource." I search about this problem, but haven't found solution. Hints:

  1. I want just use browser "Chrome Portable", Otherwise no problrm with IE and FireFox
  2. My addressbar in run: "file:///C:/Users/User-1/Desktop/WebSite1/Index.html".
  3. I don't have web server in other computers.
Gumdrop answered 5/9, 2015 at 17:39 Comment(1)
generally you will need a web server to test dc.js apps. one simple web server is built into python, maybe you can use that?Telpherage
G
3

I resolved my problem:

  1. Create shortcut and open properties of that.
  2. add --allow-file-access-from-files to end of target field's string.
Gumdrop answered 6/9, 2015 at 7:31 Comment(2)
can you provide some screen shot or details ? i have the same problem and dont understang how to do thisAlack
Just start Chrome with command and arg: C:\PathTo\Chrome.exe" --allow-file-access-from-files for Windows and open -a "Google Chrome" -n --args --allow-file-access-from-files for macOS. (simple but unsafe)Ligialignaloes
A
5

If you're not married to Chrome, you can use Firefox. It works by default.

Allene answered 26/2, 2017 at 2:43 Comment(0)
S
4

I had a similar issue before and I resolved it with an easy approach. You can't get data from .csv file because host and protocol are different.

To fix this issue, you should run a simple web server. The following example would work.

npm install -g http-server

http-server

Spenser answered 26/5, 2019 at 12:57 Comment(1)
Wonderful! It works well for me. Thank you.Georgiegeorgina
G
3

I resolved my problem:

  1. Create shortcut and open properties of that.
  2. add --allow-file-access-from-files to end of target field's string.
Gumdrop answered 6/9, 2015 at 7:31 Comment(2)
can you provide some screen shot or details ? i have the same problem and dont understang how to do thisAlack
Just start Chrome with command and arg: C:\PathTo\Chrome.exe" --allow-file-access-from-files for Windows and open -a "Google Chrome" -n --args --allow-file-access-from-files for macOS. (simple but unsafe)Ligialignaloes
B
2

If you dont want to use a local web server, you can install the CORS extensionfrom the chrome web store.

  1. Go to https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
  2. Install the CORS extension
  3. Enable the extension (you can see its icon next to the address bar)
  4. Open you html file
Besnard answered 5/9, 2015 at 20:33 Comment(2)
I use portable chrome.Gumdrop
I have added and enabled the extension but the solution is not working.Sachsen

© 2022 - 2024 — McMap. All rights reserved.