问题
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:
- I want just use browser "Chrome Portable", Otherwise no problrm with IE and FireFox
- My addressbar in run: "file:///C:/Users/User-1/Desktop/WebSite1/Index.html".
- I don't have web server in other computers.
回答1:
If you're not married to Chrome, you can use Firefox. It works by default.
回答2:
I resolved my problem:
- Create shortcut and open properties of that.
- add --allow-file-access-from-files to end of target field's string.
回答3:
If you dont want to use a local web server, you can install the CORS extensionfrom the chrome web store.
- Go to https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
- Install the CORS extension
- Enable the extension (you can see its icon next to the address bar)
- Open you html file
回答4:
I have the same issue before. You don'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 should work.
npm install -g http-server
http-server
来源:https://stackoverflow.com/questions/32415937/d3-js-load-csv-file-from-chrome