0

New to Dojo and I am just trying to get a basic Hello world module working in dojo/MVC and can't seem to get it to work. I keep getting either

no response / errors at all or cryptic Syntax errors in dojo.js e() h.injectUrl/h()

is what it says when using FireFox / Firebug. I am using 1.8 and have tried both the CDN and local copies.

Here is the code below.

Index.cshtml

    <script src="~/Scripts/dojo/dojo.js" data-dojo-config="async: true, isDebug: true, parseOnLoad: true"></script><script>
    // Require default stuff and new module
    require([
                "~/Scripts/dojoDemo/newModule"
    ],
    function (newModule) {
        newModule.setText("greetings", "Hello peoples");
        settimeout(function () {
            newModule.restoreText("greeting");
        }, 3000);
    });</script><h1 id="greetings">What up</h1>

<br/>
<br/>

newModule.js

define([
    // Define the dependencies
    "dojo/dom"], 
    // Create this function to call new module
    function (dom) {
        var oldText = {};
        return {
            setText: function (id, text) {
                var node = dom.byId(id);
                oldText[id] = node.innerHTML;
                node.innerHTML = text;
            },
            restoreText: function (id) {
                var node = dom.byId(id);
                node.innerHTML = oldText[id];
                delete oldText;
            }
        };
    });

1 Answer 1

1

You need to specify the path to the module in the dojo config and not the require call. paths map the top level module name to where the files are located to the server. By default, the file path is relative to dojo.js

<script src="~/Scripts/dojo/dojo.js" 
  data-dojo-config="async: true, isDebug: true, parseOnLoad: true, 
     paths: { dojoDemo: '../dojoDemo' }">
</script>
<script>
  require(["dojoDemo/newModule", "dojo/domReady!"], function (newModule) {
      newModule.setText("greeting", "Hello peoples");
      setTimeout(function () {
          newModule.restoreText("greeting");
      }, 3000);
  });
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

Excellent Craig. Now I'm getting into the module, but on the var node = dom.byId(id), I am getting node as undefined. Basically it is not seeing the h1 tag with the id of 'greetings'. I did a break in the module to make sure that it is greetings that is being passed in. There is a missspelling in my example above not adding the 's' on greetings. that is fixed and it is still not finding it. Thanks again
Try requiring "dojo/domReady!". See dojotoolkit.org/reference-guide/1.8/dojo/domReady.html
"dojo/ready" is something you will want to know about as well. dojotoolkit.org/reference-guide/1.8/dojo/ready.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.