"Origin null is not allowed by Access-Control-Allow-Origin" in Chrome. Why?

78,661

Solution 1

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.

Solution 2

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

Solution 3

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.

Share:
78,661
Moss
Author by

Moss

Updated on March 23, 2020

Comments

  • Moss
    Moss about 4 years

    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.

  • Moss
    Moss about 13 years
    Hmm. I try what you say but still get the same error. Maybe I am starting Chrome wrong?
  • chrismarx
    chrismarx almost 13 years
    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
  • Pointy
    Pointy almost 12 years
    @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.
  • d2vid
    d2vid over 11 years
    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 superuser.com/questions/157484/…
  • Gere
    Gere about 11 years
    works!. thanks. For MAC OS X is the better solution.
  • Phyxx
    Phyxx almost 11 years
    works in Linux too. This is a great solution for those that need a quick web server.
  • GeekyOmega
    GeekyOmega almost 11 years
    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.
  • T J
    T J over 9 years
    this should be a comment...