Search code examples
javascriptdojo

Dojo Require not working


I am just trying to do some basic dojo and dijit work. I can't seem to get the new require() function to work right in 1.7. For some reason my code is logging errors to the console and the widgets are not being parsed. Here is the code:

<html>
    <head>
        <title>Fun with Button Clicking!</title>


        <link rel="stylesheet" type="text/css" href="../dojo/dojo/dojo-release-1.7.2-src/dojo/dojo.css" />
        <link rel="stylesheet" type="text/css" href="../dojo/dojo-release-1.7.2-src/dijit/themes/tundra/tundra.css" />

        <script>
        // Instead of using data-dojo-config, we’re creating a dojoConfig object
        // *before* we load dojo.js; they’re functionally identical.
        var dojoConfig = {
            async: true,
            parseOnLoad: true

        };
    </script>
    <script type="text/javascript" data-dojo-config="async: true" src="../dojo/dojo-release-1.7.2-src/dojo/dojo.js" ></script>

        <script type="text/javascript">
        require(["dojo/parser", "dijit/form/TextBox",  "dijit/form/Button", "dijit/form/NumberSpinner"], function(parser, textBox, button, spinner) {
            dojo.connect(dojo.byId("foo"), "onclick", function(evt) {
                console.log("connect fired for DOM Node onclick");
            });

            dojo.connect(dijit.byId("foo"), "onclick", function(evt) {
                console.log("connect fired for dijit onclick");    //never!
            });

            dojo.connect(dijit.byId("foo"), "onClick", function(evt) {
                console.log("connect fired for dijit onClick");
            });
        }); 
        </script>
    <head>
    <body class="tundra">

        <label>Spinner</label>
        <input data-dojo-type="dijit.form.NumberSpinner" name="spinna" constraints="{min:0,max:100}" value=100 />

        <button id="foo" data-dojo-type="dijit.form.Button" onclick="foo">click me
            <script type="dojo/method" event="onClick" args="evt">
                console.log("Button fired onClick");
            </script>
        </button>
    </body>
</html>

I am seeing the following error several times in firebug:

Error: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "file:///D:/dev/demo/dojo/dojo-release-1.7.2-src/dojo/_base/xhr.js Line: 735"]
()Deferred.js (line 295)
(undefined=""GET"", undefined="[object Object]")xhr.js (line 738)
lates/TextBox.html",false,(undefined="function (text) {theCac...}delete pending[url];})")text.js (line 17)
",(undefined="function (a1", undefined=" a2", undefined=" a3) {return contextRequire(a1", undefined=" a2", undefined=" a3", undefined=" module", undefined=" result);})", undefined="(function (def) {module...ule);checkComplete();})")text.js (line 92)
(undefined="[object Object]")dojo.js (line 1216)
(undefined="[object Object]")dojo.js (line 1038)
id]) {injectPlugin()dojo.js (line 93)
undefined = "modules[mid] = pluginRe...oPluginResource.mid];})"
(undefined="[object Object]")dojo.js (line 1030)
(undefined="[object Object]")dojo.js (line 1072)
(undefined="[object Object]")dojo.js (line 1132)
()dojo.js (line 1154)
()dojo.js (line 1323)
(undefined="[object Event]")

Anyone know what this is all about?


Solution

  • I don't believe Dojo supports loading from the file system. This bug does mention a workaround that might work for you.

    http://bugs.dojotoolkit.org/ticket/12104