Error: “Origin null is not allowed by Access-Control-Allow-Origin” when loading an XML file with JQuery's ajax method

后端 未结 5 1736
我在风中等你
我在风中等你 2020-11-30 10:27

This is my code:

this.loadMap = function () {
    this._map = null;
    this._width = 0;
    this._height = 0;
    this._playerX = 0;
    this._playerY = 0;
         


        
5条回答
  •  无人及你
    2020-11-30 10:38

    I had this same issue with Chrome (Version 20.0.1132.57) and using --allow-file-access-from-files didn't work for me (on Ubuntu 12.04).

    But, using the command python -m SimpleHTTPServer in the directory that holds the localfiles I'm trying to test with allows me to work around the problem. That command launches an HTTP server that serves the current directory tree at http://localhost:8000/

    So, if I have a file test.html that uses an ajax call for a file in the same dir I can use http://localhost:8000/test.html and Chrome will be ok with it. For me, this is fine for local dev/testing.

    I came across that command on www.commandlinefu.com.

提交回复
热议问题