Login Register

Hello World - Dojo for the Attention-Impaired

The purpose of this tutorial is to provide a starting point for users who are new to Dojo. Whilst every effort is made to introduce as much as possible about Dojo, it is impossible to include more of the detailed information since to do so would be counterproductive and confusing to new users. For more information on the concepts introduced here, please see the links to other resources at the end of this document (Finding More Resources).

Requirements

Obviously, you need Dojo first! You can get the latest stable build from http://download.dojotoolkit.org. Next you need a web server. Whether it's hosted offsite or onsite, on Linux or Windows or Mac ... matters naught. The Dojo JavaScript library is simply pulled from your web server to the browser as needed. However, the AJAX examples in this document require a server-side scripting language like PHP or ASP.

The Dojo and Dijit code, which runs on the client browser, is certified to run on IE 6 and 7, Firefox 2, and Safari.

Setting Up Dojo

First, you should create a directory on the web server. We'll call ours HelloWorldTutorial. Then create a directory called dojoroot underneath it. Finally, use your favorite unzipping tool to unzip Dojo into /HelloWorldTutorial/dojoroot. It'll look like this when you're done:

debugging9.png

Getting Started

Once we have setup the directory and file structure for the tutorial, we will need to setup the JavaScript component of our HTML page. Have a look at the code below:

<html>
  <head>
    <title>Dojo: Hello World!</title>

    <!-- SECTION 1 -->
    <style type="text/css">
        @import "dojoroot/dijit/themes/tundra/tundra.css";
        @import "dojoroot/dojo/resources/dojo.css"
    </style>
    <script type="text/javascript" src="dojoroot/dojo/dojo.js"
      djConfig="parseOnLoad: true">
</script>
  </head>

  <body class="tundra">
  </body>
</html>

As it can be seen above, the page is a just a standard HTML skeleton with three things:

  • A couple of CSS style sheets. The one marked Tundra is the theme we will use from Dijit for this example. There
    are other themes available.
  • A script element inserted into the head section. This script element is responsible for loading the base Dojo script that provides access to all the other Dojo functionality that we will use.
  • Lastly, we place the tundra CSS class in the body tag.

Creating a Button Widget

Ok, now for the exciting part! In this example we're going to create a Button widget with the text 'Hello World!'. In the case of the Button widget, three visual states (mouseOut, mouseOver, and mouseDown) are available which means that we are able to enhance the user's experience somewhat.

The first step in creating the widget is telling Dojo to load the appropriate modules. In the header, add another section (hereafter referred to as section 2) below section 1 as follows:

<!-- SECTION 2 -->
    <script type="text/javascript">
       // Load Dojo's code relating to the Button widget
       dojo.require("dijit.form.Button");
    </script>

The dojo.require line instructs Dojo to load the Button widget. If you were to omit this line, the markup code for the button would not be evaluated by Dojo upon loading, resulting in a plain HTML button instead of what you expect.

After making the changes, insert the following code into the body section of the HTML:

<button dojoType="dijit.form.Button" id="helloButton">Hello World!</button>

The key attribute of this HTML element to notice is the dojoType attribute. The dojoType attribute is responsible for instructing Dojo on how to process the element when the page is loading. In this case we've used a button element for the button though we could have used an input element - Dojo will work with either as long as the dojoType attribute is present. It is worth noting that if we did use an input element, we would have to specify the button's text by using adding a caption attribute that contained the desired text.

Connecting an Event to the Widget

A button is all well and good, but what about getting it to do something when it's clicked? We could just specify an onClick event handler for the button, but there's another, more efficient way - the Dojo event system!

The easiest way to attach an event to a button is through a script tag. But not just any script tag ... this one has a type of dojo/method, like this:

<button dojoType="dijit.form.Button" id="helloButton">
        Hello World!
        <script type="dojo/method" event="onClick">
           alert('You pressed the button');
        </script>
    </button>
    }

Pretty simple, eh? Putting the script inside the tag body makes a good deal of sense. And you can harness the full power of DOM Level 2 events inside the script. That means you can detect SHIFT and CTRL keys, get all sorts of event properties, and bubble events up through the HTML tree. If you've ever used Level 2 events, you know how IE and Firefox use different syntax. In Dojo, the same functions work in any supported browser. That's powerful stuff!

Reading Data from the Server

Having an alert pop up when we press the button is great, but what if we want to retrieve some data from the server? Again, Dojo comes to the rescue with an easy method of accomplishing this - dojo.xhrGet. For easy reference, the code for this section is available as HelloWorld-Section5.html and response.txt in the attachments section.

To get started, we first need a callback function to handle the data to be returned from the server. Insert the following code into the header:

<script>
       function helloCallback(data,ioArgs) {
          alert(data);
       }       
       function helloError(data, ioArgs) {
          alert('Error when retrieving data from the server!');
       }
</script>

The two arguments to the functions (data, and ioArgs) are important - don't leave any of them out! The first argument (data) contains the data sent back from the server, whilst the second argument contains a Dojo I/O Bind object. Only the first concerns us right now.

The next step is to link the click of the button to the server request. To do this, modify the following code:

<script type="dojo/method" event="onClick">
    alert('You pressed the button');
</script>

To this:

<script type="dojo/method" event="onClick">
   dojo.xhrGet({
        url: 'response.txt',
        load: helloCallback,
        error: helloError
   });
</script>

The above code basically tells Dojo to query the URL specified by url and to use the function specified by handler to process the response from the server.

Finally, we need to create another file in the same directory as HelloWorld.html called response.txt. In this file, place the text 'Welcome to the Dojo Hello World Tutorial'.

Now, when the button is clicked, a JavaScript alert should display the text from the response.txt file. Dojo-Easy!

Next, we'll look at doing something meaningful with that server request.

Sending Data to the Server Using GET

It's all well and good retrieving static data from the server, but it is hardly a widely used situation in real life. So, instead of simply requesting data from the server we also will send it some information for it to process. In this section, we'll use the GET method whilst in the next section we'll use the POST method. For easy reference, the code for this section is available as HelloWorld-Section6.html in the attachments section. Server side code is also available as HelloWorldResponseGET. where type is ASP ('.asp'), PHP ('.php'), ColdFusion ('.cfm'), or Java ('.jsp').

Firstly, in the markup section of the HelloWorld.html file (i.e. the body section), we need to add another element - an input element. So, change the code in this section from:

<button dojoType="Button" widgetId="helloButton">
    <script type="dojo/method" event="onClick">
    dojo.xhrGet({
        url: 'response.txt',
        load: helloCallback,
        error: helloError
    });
    </script>
</button>

to:

<button dojoType="dijit.form.Button" id="helloButton">
        Hello World!
        <script type="dojo/method" event="onClick">
        dojo.xhrGet({
           url: 'HelloWorldResponseGET.php',
           load: helloCallback,
           error: helloError,
           content: {name: dojo.byId('name').value }
        });
        </script>
     </button>
     Please enter your name: <input type="text" id="name">

Before we go any further - it is important to mention that the url property in the dojo.xhrGet function call must be set to the file that is appropriate to your environment. If you are using an ASP server then the value must read 'HelloWorldResponseGET.asp' instead of 'HelloWorldResponseGET.php' Likewise, if you are using a ColdFusion server then the value must read 'HelloWorldResponseGET.cfm' instead of 'HelloWorldResponseGET.php'. Finally, if you are using a Java server (JSP) then the value must read 'HelloWorldResponseGET.jsp' instead of 'HelloWorldResponseGET.php', or if you are using a Perl server then the value must read 'HelloWorldResponseGET.pl' instead of 'HelloWorldResponseGET.pl'. The code for these files is in the sections below, and is also available as attachments to this tutorial.

In the code above, you will notice that there is a new property that has been passed to the dojo.xhrGet function. This property - content - allows the programmer to send arbitary values to the server as parameters. In this case, since we are using the default method of dojo.io.bind which is GET, the server side script will have the value of the textbox available to it as a the GET parameter 'name'. It is worth mentioning that if the script expected the parameter under a different name (such as 'myName'), we would simply change the content property to be (note the change of 'name' to 'myName' on the left of the assignment operator ':'):

content: {myName: dojo.byId('name').value }

Since we've not used it before, it is also worth noting the call dojo.byId('name').value. Quite simply, this call is a shortcut for the standard document.getElementById(..) function.

Finally, if you enter your name into the text box and you click the 'Hello World' button, an alert box should appear with the message 'Hello , welcome to the world of Dojo!' where is the name you entered into the text box.

Here are the server side scripts. A few of them are downloadable at the bottom of this page (the website content management system doesn't allow .jsp or .cfm files).

Using a PHP Server

<?php
  /*
  * HelloWorldResponseGET.php
  * --------
  *
  * Print the name that is passed in the
  * 'name' $_GET parameter in a sentence
  */


  header('Content-type: text/plain');
  print "Hello {$_GET['name']}, welcome to the world of Dojo!\n";
?>

Using an ASP Server

<%
  '
  ' HelloWorldResponseGET.asp
  ' --------
  '
  ' Print the name that is passed in the
  ' 'name' GET parameter in a sentence
  '

  response.ContentType="text/plain"
  response.write("Hello " & request.querystring("name") & ", welcome to the world of Dojo!\n")
%>

Using a ColdFusion Server


Hello, #url.name#, welcome to the world of Dojo!

Using a Java Server (JSP)

<%
  /*
  ' HelloWorldResponseGET.jsp
  ' --------
  '
  ' Print the name that is passed in the
  ' 'name' GET parameter in a sentence
  */

  response.setContentType("text/plain");
%>
Hello <%= request.getParameter("name") %> , welcome to the world of Dojo!

Using a Perl Server

#!/usr/bin/perl
#
#  ' HelloWorldResponseGET.pl
#  ' --------
#  '
#  ' Print the name that is passed in the
#  ' 'name' GET parameter in a sentence
#
use strict;
use CGI;
my $cgi = CGI::new();
print $cgi->header(-type => "text/html; charset=utf-8");
print "Hello " . $cgi->param('name') . ", welcome to the world of Dojo!\n";

Sending Data to the Server Using POST

Using GET data is all well and good, but sometimes you want to use Dojo to improve the user's experience when using a traditional HTML form. As usual, Dojo has a very nice way of making this easier. Again, the code for these files is in the sections below, and are also available as attachments to this tutorial. Additionally, as with the last section, you will need to change the 'url' property to point to the file that is appropriate to your environment.

First, we need to change the markup in the body of HelloWorld.html from:

<br>
    Please enter your name: <input type="text" id="name">

to:

<br>
    <form id="myForm" method="POST">
      Please enter your name: <input type="text" name="name">
    </form>

Next we need to change the dojo/method:

<script type="dojo/method" event="onClick">
        dojo.xhrGet({
           url: 'HelloWorldResponseGET.php',
           load: helloCallback,
           error: helloError,
           content: {name: dojo.byId('name').value }
        });
</script>

to:

<script type="dojo/method" event="onClick">
   // Don't forget to replace the value for 'url' with
   // the value of appropriate file for your server
  // (i.e. 'HelloWorldResponsePOST.asp') for an ASP server
    dojo.xhrPost({
        url: 'HelloWorldResponsePOST.php',
        load: helloCallback,
        error: helloError,
        form: 'myForm'
   });
</script>

As can be seen from the code above, we've changed dojo.xhrGet to dojo.xhrPost. We removed the 'content' property and replaced it with a new property 'form'. This basically informs the dojo.xhrPost function that it needs to use the form 'myForm' as the source for the data in the call.

As with the last section, entering your name and clicking 'Hello World!' should yield a message such as 'Hello , welcome to the world of Dojo!' where is the name you entered into the text box.

Using a PHP Server

<?php
  /*
  * HelloWorldResponsePOST.php
  * --------
  *
  * Print the name that is passed in the
  * 'name' $_POST parameter in a sentence
  */


  header('Content-type: text/plain');
  print "Hello {$_POST['name']}, welcome to the world of Dojo!\n";
?>

Using an ASP Server

<%
  '
  ' HelloWorldResponsePOST.asp
  ' --------
  '
  ' Print the name that is passed in the
  ' 'name' $_POST parameter in a sentence
  '

  response.ContentType="text/plain"
  response.write("Hello " & request.form("name") & ", welcome to the world of Dojo!\n")
%>

Using a ColdFusion Server


Hello, #form.name#, welcome to the world of Dojo!

Using a Java Server (JSP)

<%
  /*
  ' HelloWorldResponsePOST.jsp
  ' --------
  '
  ' Print the name that is passed in the
  ' 'name' POST parameter in a sentence
  */

  response.setContentType("text/plain");
%>
Hello <%= request.getParameter("name") %> , welcome to the world of Dojo!

Using a Perl Server

#!/usr/bin/perl
#
#  ' HelloWorldResponsePOST.pl
#  ' --------
#  '
#  ' Print the name that is passed in the
#  ' 'name' POST parameter in a sentence
#
use strict;
use CGI;
my $cgi = CGI::new();
print $cgi->header(-type => "text/html; charset=utf-8");
print "Hello " . $cgi->param('name') . ", welcome to the world of Dojo!\n";

Finding more resources

I hope you've enjoyed this tutorial and found it informative. No doubt though, you will need more information on Dojo and how it and it's widgets work. Below is a list of links that will point you in the right direction.

Contacting the Author

Thinking of making modifications to this document? Want to make suggestions / constructive criticism?

If so, please contact me (Lance Duivenbode) at dojo AT duivenbode DOT id DOT au. Feedback is always welcome since it helps me improve my documentation - both now and in the future. Thanks!

Changelog

  • 17th November 2007 - Pulled kicking and screaming into the Dojo 1.0 era (Craig Riecke)
  • 28th June 2006 - Addition of Perl Server examples for GET and POST (courtesy of Gareth Tansey)
  • 21th June 2006 - Modification for compatibility with 0.3.x release (Bill Keese)
  • 22th May 2006 - Addition of Java Server (JSP) examples for GET and POST (courtesy of Kexi)
  • 19th May 2006 - Addition of ColdFusion examples for GET and POST (courtesy of Matthew Reinbold)
  • 8th May 2006 - Initial Public Release
AttachmentSize
HelloWorldResponseGET.asp_.txt273 bytes
HelloWorldResponseGET.php_.txt253 bytes
HelloWorldResponseGET.pl_.txt327 bytes
HelloWorldResponsePOST.asp_.txt267 bytes
HelloWorldResponsePOST.php_.txt256 bytes
HelloWorldResponsePOST.pl_.txt329 bytes
response.txt16 bytes

Post Script Error

The following script used for post method doesn't work:

    dojo.xhrPost({
        url: 'HelloWorldResponsePOST.jsp',
        load: helloCallback,
        error: helloError,
        form: 'myForm'
   });

event="onclick" should be event="onClick" otherwise nothing happens.

just to note: you use

just to note: you use "onClick" with dojo/method script type inside of a button because dojo/method is actually replacing the onClick: function(e){ } in Button.js on the fly. "onClick" is used with buttons as the click handler. "onclick" is the dom event, and you can catch that via dojo.connect() just fine.

Use the post,you should add

Use the post,you should add the input tag attribute "name",not the attribute "id",if you use get,ok,it does work well.if you use post,add the text input type="text" name="name",otherwise,you may get
the message:Hello null,welcome....

I am getting an error 'dojo' is undefined

// Load Dojo's code relating to the Button widget
       dojo.require("dijit.form.Button");

Change routes

Change routes, depending on where your page is an example.
I change this

@import "dojoroot/dijit/themes/tundra/tundra.css";
@import "dojoroot/dojo/resources/dojo.css"

 

by

@import "dijit/themes/tundra/tundra.css";
@import "dojo/resources/dojo.css"

 

Because my page is \js\dojoroot\helloworld.html

the location of "<script src."dojo.js".>" causes the problem

I do it with jsp.According to the turorial,I put the js ref
script type="text/javascript" src="dojoroot/dojo/dojo.js"
djConfig="parseOnLoad: true".....
between head tag,always get the error "dojo undefined".Then,I put it just under the <%page ....%>,yeah,that's right!

dojo is not defined

dojo.require("dijit.form.Button");

Post and Get part

The article is very helpful but the Get and Post (server side) part needs to be revisited especially for java/jsp; the example does not seem to work for me !

Post and Get part can not work for JSP

The article is very helpful but the Get and Post (server side) part needs to be revisited especially for java/jsp; the example does not seem to work for me !

Yeah. The java/jsp can not work for me either. (Tomcat Server).
Poped message always 'Hello null , welcome to the world of Dojo!'.

xhrGet to get any url

Is that possible to use xhrGet to get content from any url. for example to get content from http://google.com.

additional attributes in tags

Hello, i'm using XHTML in my new page and also at my work. The additanal attributes will be marked as wrong or unknown attributes. Is their a DTD or Schema for these attributes.

Syncronous execution

when performing a server GET via xhrGet you can add the sync: true option to force this operation to act synchronously, ie. browser waits for xhrGet to complete

dojo.xhrGet({
        url: 'response.txt',
        sync: true,
        load: helloCallback,
        error: helloError
   });

JSP problems?

It works fine for me. I just put the .jsp file in the webapps/ROOT/HelloWorldTutorial directory and it worked. It's calling your JSP, so I think the problem is in your JSP setup. Try this:

http://localhost:8080/HelloWorldTutorial/HelloWorldResponseGET.jsp?name=...

(or whatever your port number is). Does this give "foobar" in the response message or "null"?

Permission denied to call method XMLHttpRequest.open

If you are getting this error with the ajax call in FireFox:

Error: [Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]

your html file (with the Dojo ajax call in it) may be loaded with file://. It needs to be loaded from the same (tomcat) server that is serving the JSON jsp, then this error will go away.

/r:b:

HelloWorld tutorial - server response

Not working for me. Instead of returning only the value in the response.write statement, the server is returning the full text of the helloWorldResponseGET.asp file. Ie. instead of executing the ASP it is treating it as plain text. Same thing happens if I use the POST method.

hmmm

Ok, the main reason the JSP version returns null in the alert tag is that you need to remove 'myForm' and replace with just myForm in the xhrPost

Tutorial code bug

I have spent a bit of time going through the tutorial and can't get the helloButton to trigger the onClick event (using dojo/method), my code is shown below:

<head>
    <title>Dojo: Hello World!</title>
    <!-- SECTION 1 -->
    <style type="text/css">
        @import "dijit/themes/tundra/tundra.css";
        @import "dojo/resources/dojo.css"

<!-- SECTION 2 -->
    <script type="text/javascript">
       // Load Dojo's code relating to the Button widget
       dojo.require("dijit.form.Button");
    </script>
    </style>

    <script type="text/javascript" src="dojo/dojo.js"
      djConfig="parseOnLoad: true">
</script>

  </head>
  <body class="tundra">
  <p id="test">
  here is a test
 
 

 

The problem is with the dojo/method onClick not working

  <button dojoType="dijit.form.Button" id="helloButton">
<script type="dojo/method" event="onClick">
console.log("something happened");
</script>
 Hello World!
</button>
  </body>

The trouble is that the console.log is not being triggered. I have looked at the source code but can't work it out. Has anone got any ideas (i have no 404 and have used firebug to debug). I'd like to get the Helloworld demo working and post the full HTML on this page so others don't have the trouble I have.

Thanks for your help

please testline /* GeSHi

please test

line

move before SECTION 1

check the location of HTML.......

i guess the problem is the location of html file.

folder levels should be like this

dojoroot(folder)
---dijit
---dojo
---dojox
your html file(same level as of dojoroot is)

in the html file change the paths of import statements and dojo.js(just add dojoroot in the beginning)

it should work. try it....

RE: check the location of HTML.......

As I said in my post, there are no 404 errors so the HTML can see all the relevant includes. Is there a special relevance to the dojoroot? If I am using dojo do I have to have exactly the path dojoroot/dojo? Could someone post the full working HTML that has been unit tested, this would be really helpful instead of having to follow the tutorial through (which still has errors in it, e.g. the dijit reference being wrong).

Thanks for your help

As torii mentioned, you need

As torii mentioned, you need to move your:

<script type="text/javascript" src="dojo/dojo.js"
      djConfig="parseOnLoad: true">
</script>

to before the first reference to any dojo js code, although it is OK to be after the style/import css section. No dojo actions can occur unless dojo.js is first loaded. Calling a dojo function/method prior to dojo.js being loaded will do nothing, although if you use the Firebug extension for the Firefox browser, you will likely get some helpful info in "its" console panel.

The paths to dojo script/css just has to be correct, in relation to the web site document root directory. If, in your code above, the dojo, dijit, etc. directories are subdirectories of the directory containing your index.html, you should be fine.

Update:
Just noticed that one of your script blocks is inside the style block--can't do that:

<script type="text/javascript">
       // Load Dojo's code relating to the Button widget
       dojo.require("dijit.form.Button");
    </script>
    </style>  <<<<<+++++++  no can do...

Similar non-firing of onClick event

I am having similar problems. The onClick event doesn't fire, but I see no other symptoms. The following is my current page. I have a "dojo" directory in my web root that corresponds to the "dojoroot" mentioned in the example. Is there some debug info I can turn on that might hint at why this isn't working? Note that this incorporates the earlier suggestion about moving the djConfig setting script to before the style element.

<!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=iso-8859-1" />
  <title>Hello World</title>
    <script src="dojo/dojo/dojo.js">
        djConfig="parseOnLoad: true";
    </script>
  <style type="text/css"">
     @import "dojo/dijit/themes/tundra/tundra.css";
     @import "dojo/dojo/resources/dojo.css"
  </style>
  <script>
    dojo.require("dijit.form.Button");
  </script>
 </head>
 <body class="tundra">
  <button dojoType="dijit.form.Button" id="helloButton">
   Hello World
   <script type="dojo/method" event="onClick">
      alert("You pressed the button.");
   </script>
  </button>
 </body>

Looks like most of the

Looks like most of the problems are typos. I believe this works (with css/script pathing changed to match my PC):

<!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=iso-8859-1" />
                <title>Hello World</title>
        <script type="text/javascript" src="js/dojotoolkit/dojo/dojo.js"
            djConfig="parseOnLoad: true">

        </script>
                <style type="text/css"">
                        @import "js/dojotoolkit/dijit/themes/tundra/tundra.css";
                        @import "js/dojotoolkit/dojo/resources/dojo.css";
                </style>
                <script type="text/javascript">
                        dojo.require("dijit.form.Button");
                </script>
        </head>
        <body class="tundra">
                <button dojoType="dijit.form.Button" id="helloButton">
                        Hello World
                        <script type="dojo/method" event="onClick">
                                console.log('you pressed the button');
                                alert("You pressed the button.");
                        </script>
                </button>
        </body>

The main problem was putting the closing script > bracket for the script containing parseOnLoad in the wrong place. This kept the button from becoming a dijit.form.Button--could tell by its appearance and also by trying to locate it by dijit.byId('helloButton'). Other more minor, but should still be coded properly, were omission of type="text/javascript" in the script tags, omission of the semi-colon at the end of the second css import, etc.

You are on your way! Enjoy...

That worked a treat - thanks

That worked a treat - thanks a lot for your help

Great code from frankf!

Frankf, thanks so much for providing that bug-free code. Firebug was spewing out lots of errors until I found your code. I would have spent all night and day trying to figure it out.

<code> does not render

Sample code does not render for me in Safari 3.1 on Windows, or Firefox 3b4 on Linux. Instead of appearing as unparsed html code, it appears as parsed html code. So, for example, the button widgets appear as actual buttons. It is not clear to me whether this is a client-side or server-side mistake.

Problem with the Forum/Book Software

In the last day?, when code is posted inside <code> tags, the code is interpreted rather than left unmolested. A change to the drupal or ?? must have caused this...

I went back and edited my two postings on this page, replacing the code tags with html and/or js tags, and the sample code was displayed properly, so, broken "code" tag filtering.

Your posting rendered just

Your posting rendered just fine here: http://www.dojotoolkit.org/book/dojo-book-0-9/hello-world-tutorial#comme...

Unfortunately, the main article has the problem I spoke of above. Not sure when it started; I just checked it today. Maybe if the author would repost...?

Ah, it looks like it's

Ah, it looks like it's working again.

Dustin Machi

Dustin Machi

Dustin Machi

Dustin Machi

TurboGears server

after managing to implement the code of this nice tutorial with TurboGears on the server side, here is how that part looks like in Python.

in controller.py:

    @expose(template="myproject.templates.index")
    def index(self):
        return dict()

    @expose("json")
    def HelloWorldResponse(self, name):
        return "Hello " + name + ", welcome to the world of Dojo!"

more modifications:

  • put response.txt in the static folder and use url: 'static/HelloWorldTutorial/response.txt'
  • url: HelloWorldResponse in xhrGet/xhrPost

that's all folks!

dojo.js errors!

The scripts/styles seem to be getting loaded but these errors are thrown when the page loads:

failed loading dojo/../dijit/form/_FormWidget.js with error: Error: Could not load 'dijit._Templated'; last tried '../dijit/_Templated.js'dojo.js (line 20)
failed loading dojo/../dijit/form/Button.js with error: Error: Could not load 'dijit.form._FormWidget'; last tried '../dijit/form/_FormWidget.js'

Could not load 'dijit.form.Button'; last tried '../dijit/form/Button.js'
http://nicholas-dev.dri.edu/HelloWorldTutorial/dojo/dojo.js
Line 20

Any ideas?

- Nick

Ask questions in the Forum, not in the book

We're all better off if you write help questions in the Forum, not in the book pages.