50

I am working on some Javascript to run locally on my PC. I am using a jQuery CSV plugin (http://plugins.jquery.com/project/csv) to load load a csv file into javascript arrays. The script is simple:

$(function(){
 $.get("file.csv", function(data){
  stuff = $.csv()(data);
 })
})

In Firefox it works fine but in Chrome it says "Origin null is not allowed by Access-Control-Allow-Origin". What does that mean? I find all sorts of threads about cross-server stuff related to this error but I am just working with local files.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Moss
  • 3,695
  • 6
  • 40
  • 60
  • 1
    I had the same problem. It was easily solved with local server, like: XAMPP, WAMP and the like. No need for special tricks. –  Dec 07 '11 at 08:12

4 Answers4

89

Chrome doesn't believe that there's any common relationship between any two local files.

You can start it with the option "--allow-file-access-from-files" to tell it you disagree.

Thanks to the ascendant master Nick Craver for this info when I asked essentially the same question some time ago.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • Hmm. I try what you say but still get the same error. Maybe I am starting Chrome wrong? – Moss Mar 07 '11 at 23:06
  • 12
    make sure you've closed every instance of chrome that's running, otherwise it won't pick up the change. so just make sure there is no chrome.exe in process list – chrismarx May 17 '11 at 14:47
  • @user1028100 I have no idea, if it's not possible to launch Chrome on MacOS from a command line or if the option doesn't work. – Pointy Jun 21 '12 at 19:10
  • 7
    I was able to open chrome with that flag using the command "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files". I'm on OSX 10.7.4 (lion). See http://superuser.com/questions/157484/start-google-chrome-on-mac-with-command-line-switches – d2vid Sep 23 '12 at 17:52
  • 1
    Thanks to chrismarx, this is something that should be pointed out if you are neck deep in dev work. It's simple, but that can really screw up you day if you forget about it. – GeekyOmega Jul 08 '13 at 16:37
17

If you are using Mac OS X, open up the Terminal, cd to your web root and run:

python -m SimpleHTTPServer

Then open the following URL in Chrome (or any other web browser):

http://0.0.0.0:8000
WebSeed
  • 1,687
  • 1
  • 15
  • 19
2

It's like crossdomain for some unclear reason (each browser acts a bit differently regarding this issue, you could even try IE and see the results). You should try and run it through a web server, and give it an absolute path since the javascript runs locally.

Matt
  • 74,352
  • 26
  • 153
  • 180
Cu7l4ss
  • 556
  • 1
  • 8
  • 19
-1

You can try running it on your apache web server. It will work.

Madhukarah
  • 89
  • 1
  • 5