ローカルファイルで実行できないやつ
JavaScriptでCSVファイルを読み込む方法 | UX MILKで勉強してて。
function getCSV() { var req = new XMLHttpRequest();//HTTPでファイルを読み込むためのXMLHttpRequestオブジェクトを生成 req.open("get", "sample.csv", true); //アクセスするファイルを指定 req.send(null);//HTTPリクエストの発行 //レスポンスが帰ってきたらconvertCSVtoArray()を呼ぶ req.onload = function(){ convertCSVtoArray(req.responseText);//渡されるのは読み込んだCSVデータ } }
こういう感じの。ローカルで実行したら
index.html:12 Failed to load file:///Users/*/Desktop/***: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
ってエラーになった。
$ sudo /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \ --allow-file-access-from-files
で事項したらできた。
参考ページ