This is my code:
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
});
};
The error i'm getting is
"XMLHttpRequest cannot load file:///C:/wamp/www/mazegame/maze1.xml. Origin null is not allowed by Access-Control-Allow-Origin".
This same script works fine in Firefox
Run the following command to confirm the origin server returns the Access-Control-Allow-Origin header. Replace example.com with the required origin header. Replace https://www.example.net/video/call/System.generateId.dwr with the URL of the resource that's returning the header error.
Access-Control-Allow-Origin: null This value should not be used to serialize the origin of resources that use a non-hierarchical scheme. Sandboxed documents are defined as null. User agents may grant access to these documents and create a hostile document with null origin.
The Origin spec indicates that the Origin header may be set to "null". This is typically done when the request is coming from a file on a user's computer rather than from a hosted web page. The spec also states that the Origin may be null if the request comes from a "privacy-sensitive" context.
You're testing this in Chrome? What's basically happening is because you're loading the file from your filesystem instead of from a server, Chrome is setting your origin to null
even though the resource you're requesting is local to you. If you were to do this from an HTTP server such as Apache, I think it would work just fine.
Yes, Google in their blessed wisdom decided that Chrome will not permit an access to local files for rather obscure security reasons. Every two local files are considered as if they were from different domains, and accessing a local file is considered a cross-site request.
There is a workaround, but useful only in some situations: If you can run Chrome with a command line parameter --allow-file-access-from-files
, the security check will not be done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With