A very common way of loading data in your web-app is the use of
Haxe can handle json cross-platform
Crossplatform JSON API : it will automatically use the optimized native API if available. Use
-D haxeJSONto force usage of the Haxe implementation even if a native API is found. This will provide extra encoding features such as enums (replaced by their index) and StringMaps.
When you load an example locally (when you test your files on your computer instead of a server) you will get an error message:
.... from origin 'file://' has been blocked from loading by Cross-Origin Resource Sharing policy: Received an invalid response. Origin 'null' is therefore not allowed access.
To fix that you should open your files via localhost.
There are many ways to do it, but I will use the Haxe solution
We will use a rarely mentioned feature from Haxe.
You can run a web-server : Neko Web Server
And the cool part is: You don't have to install anything if you already have Haxe installed.
Neko Web Server v1.0 - (c)2006-2013 Haxe Foundation Options : -p <port> : change server port -h <host> : change server host -d <dir> : change the server base directory -log <file> : set log file -rewrite : activate pseudo mod-rewrite for smart urls
You need the path to your files (so replace
path/to/files with your own path)
nekotools server -p 2000 -h localhost -d path/to/files
and open your browser to http://localhost:2000
You can also start the web-server with it's defaults (port:2000, host:localhost)
But then you have to visit the configure-page the server by going to http://localhost:2000/server:config
(or open your terminal in the correct folder)
Read more about Neko tools: