This example follows the content of the "Dojo Basics"
First, we create a new file in the same level directory in helloworld.html, named
response.txt,内容为:
Welcome to the Dojo Hello world Tutorial
Replace the code for section 2 with the following code
<!--section 3
<script type= "Text/javascript"
Dojo.require ("dojo.io.*");
Dojo.require ("dojo.event.*");
Dojo.require ("dojo.widget.*");
Dojo.require ("Dojo.widget.Button"); The
//binding URL path. Of course, when the button is pressed, the request is sent to the Response.txt, at which point the server
//will return the content in Response.txt. This URL can be another object. Like the
//*** in struts . Do or is a servlet URL.
Function hellopressed ()
{
Dojo.io.bind ({
URL: ' response.txt ',
Handler:h Ellocallback
});
}
//process functions that return data. The three parameters are required .
Function Hellocallback (type, data, evt)
{
if (type = = ' ERROR '
Alert (' Error when retrieving data ' server! ');
Else
Alert (data);
Function init ()
{
var Hellobutton = dojo.widget.byId (' Hellobutton ');
Dojo.event.connect (Hellobutton, ' OnClick ', ' hellopressed ')
}
Dojo.addonload (init);
</script>
The above is all code.