Can't load dojo.js

As I am trying to use dojotoolkit , I am trying to run (open) the following html code in my browser as they said in the tutorial, but my browser cannot load dojo.js

At the time of troubleshooting, I found that the original url is converted like this:

File: //ajax.googleapis.com/ajax/libs/ dojo / 1.10.4 / dojo / dojo.js

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Tutorial: Hello Dojo!</title>
</head>
<body>
    <h1 id="greeting">Hello</h1>
    <!-- load Dojo -->
    <script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"
            data-dojo-config="async: true"></script>

    <script>
        require([
            'dojo/dom',
            'dojo/dom-construct'
        ], function (dom, domConstruct) {
            var greetingNode = dom.byId('greeting');
            domConstruct.place('<em> Dojo!</em>', greetingNode);
        });
    </script>
</body>
</html>

      

+3


source to share


2 answers


Use a real web server rather than browsing it from the filesystem.



While Frank is correct that adding an explicit protocol to the URL will fix this particular problem, you will inevitably run into other problems as XHR is blocked from the protocol file://

. The relative URL of the protocol you originally used will work fine if you test on a real web server that serves http or https.

+3


source


you need to add http as the protocol for the dojo.js source .

<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"
            data-dojo-config="async: true"></script>

      



It's also best to add the library files to the head tag instead of the body tag .

<head>
    <meta charset="utf-8">
    <title>Tutorial: Hello Dojo!</title>

    <!-- load Dojo -->
    <script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"
            data-dojo-config="async: true"></script>
</head>

      

+1


source







All Articles