Cannot load custom dojo module

dojomodule

I'm trying to follow the custom module tutorial at http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/modules-and-namespaces/creating-your-own-modul

I've got a local deployment of dojo at http://localhost:8081/dojo-1.3.2/dojo/dojo.js
For my custom module I've created the following javascript file at http://localhost:8081/dojo-1.3.2/explosive/space/Modulator.js:

dojo.provide("explosive.space.Modulator");
dojo.declare("explosive.space.Modulator",null,{
bob:1
});

In my html page I have the following:

<script type="text/javascript" src="http://localhost:8081/dojo-1.3.2/dojo/dojo.js"></script>
<script type="text/javascript">
dojo.require("explosive.space.Modulator");
</script>

And when I pull up my site in firefox I get the error:

Error: Could not load
'explosive.space.Modulator'; last
tried
'../explosive/space/Modulator.js'

Any ideas on what I'm doing wrong?

EDIT: After more testing it appears the code works on IE8 and IE8 compatibility mode but not in Firefox, Chrome, or Opera.

EDIT2: My html file was on a different domain but I didn't think that should make any difference. After reading Seth's comment (thanks Seth!) I tried it both ways.

I have two tomcat instances, one on port 8080 and one on port 8081. I've placed index.htm in both instances and started them both up.

http://localhost:8081/test/index.htm works in both FF and IE. http://localhost:8080/test/index.htm does not work as expected in FF, but does work in IE.

Show XmlHTTPRequests shows that FF is making a call to "GET http://localhost:8081/dojo-1.3.2/explosive/space/Modulator.js" which is coming back with an empty response for some reason.

Here's the entirety of my code for index.htm if it's any help.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <title>Create Map</title>
    <script type="text/javascript" src="http://localhost:8081/dojo-1.3.2/dojo/dojo.js"></script>
    <script type="text/javascript">
      dojo.require("explosive.space.Modulator");

      function init(){
          var eludiumFuel36 = new explosive.space.Modulator();
          alert(eludiumFuel36.bob);
      }

      dojo.addOnLoad(init);
    </script>
  </head>
  <body class="tundra">
    <h1>Hello World!</h1>
  </body>
</html>

Best Answer

It looks ok from what you have here. When you bring up the page, are you going to http://localhost:8081/testpage.html (or somesuch)? Or are you going to a different domain?

Do you have firebug installed? If not, install it and turn on 'Show XMLHttpRequests'. That will show what URL it's trying to access in the console (and any other possibly relevant errors).

Otherwise, there might be something else on the page outside of what you posted messing with dojo's load path.

Edit

When dojo does an dojo.require, it does a XHR call for the file. The includes the host and port in it. So, it's violating cross domain security when the html page is on localhost:8081 but the javascript is on localhost:8080. You can get around this by using a cross-domain build version of the file (or make sure all requests come on the same port and host). Truth be told, I'm not quite sure why IE works with the different ports though.