[SOLVED] Using GetScript to load localscript

Im trying to load a bunch of scripts one of them (marzipano.js) is local (public/js/marzipano.js) and I’m having problems on loading it. Any help would be appreciated

\imports\ui\pages\demo.js

import React from 'react';

export default class Login extends React.Component {
    componentDidMount() {
        $.getScript('http://www.marzipano.net/demos/common/es5-shim.js', function() {
            $.getScript('http://www.marzipano.net/demos/common/eventShim.js', function() {
                $.getScript('http://www.marzipano.net/demos/common/requestAnimationFrame.js', function() {
                    $.getScript('js/marzipano.js', function(data, textStatus, jqxhr) {
                        console.log(data); // Data returned
                        console.log(textStatus); // Success
                        console.log(jqxhr.status); // 200
                        console.log("Load was performed.");
                    });

                });
            });
        });
    }

    render() {
        return ( <
            div id = "pano" > </div>
        );
    }
}

The issue is that $.getScript() uses an Ajax call to load the script and Ajax calls are not allowed by default to fetch contents from your hard drive in some browsers (like Chrome) for security reasons. This would not be an issue if loading from a real web server.

1 Like

Have you tried with an absolute URL (slash before js)?

$.getScript('/js/marzipano.js', function() {
});

Hey, check the post above you

Funny, works as advertised in all browsers, Chrome/Safari/Firefox.