I'm trying to follow a melonJS tutorial. It says I should disable cross-origin request using one of two methods:
--disable-web-security
--allow-file-access-from-files**
I've tried both of these in my command prompt as such:
C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e
xe --allow-file-access-from-files
C:\Users\danniu>C:\Users\danniu\AppData\Local\Google\Chrome\Application\Chrome.e
xe --disable-web-security
When I try to run the game in Chrome I'm still getting this error:
XMLHttpRequest cannot load file:///C:/Users/danniu/Desktop/JavaScript/melonJS/data/map/area01.tmx. Cross origin requests are only supported for HTTP.
What am I doing wrong?
Thanks
The same-origin policy is a critical security mechanism that restricts how a document or script loaded by one origin can interact with a resource from another origin.
i. Turn OFF the CORS plugin, reload the app, at this time you should still get the errors which are correct. ii. Turn it back ON, reload the app, if the APIs are successful, stop here, no need to proceed to iii.
Allow CORS: Access-Control-Allow-Origin. Easily add (Access-Control-Allow-Origin: *) rule to the response header. Allow CORS: Access-Control-Allow-Origin lets you easily perform cross-domain Ajax requests in web applications. Simply activate the add-on and perform the request.
You need to use both arguments. This is how I run it on my mac.
open -a Google\ Chrome --args --disable-web-security -–allow-file-access-from-files
This is how it should be for windows:
"C:\PathTo\Chrome.exe" –allow-file-access-from-files -disable-web-security
To disable chrome web security on mac use this command on terminal
$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir="/tmp/chrome_dev_session" --disable-web-security
if $ open -a Google\ Chrome --args --disable-web-security -–allow-file-access-from-files dosen't help
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