这是我的代码:
this.loadMap = function () {
this._map = null;
this._width = 0;
this._height = 0;
this._playerX = 0;
this._playerY = 0;
this.finished = false;
this.loaded = false;
$.ajax({
type: "GET",
url: "maze1.xml",
dataType: "xml",
success: this.parseXmlMap,
context: this
});
};
我得到的错误是
"XMLHttpRequest cannot load file:///C:/wamp/www/mazegame/maze1.xml. Origin null is not allowed by Access-Control-Allow-Origin".
同样的脚本在 Firefox 中运行良好
最佳答案
您是在 Chrome 中测试这个吗?基本上发生的事情是因为你是从你的文件系统而不是从服务器加载文件,Chrome 将你的来源设置为 null 即使你请求的资源对你来说是本地的。如果您要从 Apache 等 HTTP 服务器执行此操作,我认为它会工作得很好。
关于jquery - 错误 : "Origin null is not allowed by Access-Control-Allow-Origin" when loading an XML file with JQuery's ajax method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5396527/