XMLHttpRequest Origin null is not allowed Access-Control-Allow-Origin for file:/// to file:/// (Serverless)

前端 未结 9 777
醉梦人生
醉梦人生 2020-11-22 03:30

I\'m trying to create a website that can be downloaded and run locally by launching its index file.

All the files are local, no resources are used online.

Wh

相关标签:
9条回答
  • 2020-11-22 04:16

    You can try putting 'Access-Control-Allow-Origin':'*' in response.writeHead(, {[here]}).

    0 讨论(0)
  • 2020-11-22 04:17

    This solution will allow you to load a local script using jQuery.getScript(). This is a global setting but you can also set the crossDomain option on a per-request basis.

    $.ajaxPrefilter( "json script", function( options ) {
      options.crossDomain = true;
    });
    
    0 讨论(0)
  • 2020-11-22 04:20

    Essentially the only way to deal with this is to have a webserver running on localhost and to serve them from there.

    It is insecure for a browser to allow an ajax request to access any file on your computer, therefore most browsers seem to treat "file://" requests as having no origin for the purpose of "Same Origin Policy"

    Starting a webserver can be as trivial as cding into the directory the files are in and running:

    python -m SimpleHTTPServer
    
    0 讨论(0)
提交回复
热议问题