[Solved-5 Solutions] “Cross origin requests are only supported for HTTP” error when loading a local file



Error Description :

    • When we try to load a 3D model into Three.js with JSONLoader, and that 3D model is in the same directory as the entire website.
    • We get the "Cross origin requests are only supported for HTTP." Error.

    Solution 1:

    • If we are loading the model using either file:// or C:/, which stays true to the error message as they are not http://
    • So we can either install a webserver in your local PC or upload the model somewhere else and use jsonp and change the url to http://example.com/path/to/model

    Solution 2:

    • In Chrome we can use this flag:
    --allow-file-access-from-files
    
    click below button to copy the code. By - JavaScript tutorial - team

    Solution 3:

    • Just change the url to instead of localhost. If we open the html file from local, we should create a local server to serve that html file, the simplest way is using Web Server for Chrome . That will fix the issue.

    Solution 4:

    • For those on Windows without Python or Node.js, there is still a lightweight solution: Mongoose
    • All we do is drag the executable to wherever the root of the server should be, and run it. An icon will appear in the taskbar and it'll navigate to the server in the default browser.
    • Also, Z-WAMPis a 100% portable WAMP that runs in a single folder, it's awesome. That's an option if you need a quick PHP and MySQL server.

    Solution 5:

    • In an Android app - for example, to allow JavaScript to have access to assets via file:///android_asset/ -
      • use setAllowFileAccessFromFileURLs(true) on the WebSettings that we get from calling getSettings() on the WebView.

    Related Searches to “Cross origin requests are only supported for HTTP” error when loading a local file