现在手头的项目前台是用dojo来做的,客户的要求总是BT的,上个项目是用Flex做前台,和dojo一样,开发起来让人有点费力不讨好。总之,客户就是上帝,上帝的要求自然要努力去满足。
还是从经典的HelloWorld开始接触dojo喽。
- <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>
- <!--section 2-->
- <script type="text/javascript">
- // Load Dojo's code relating to the Button widget
- dojo.require("dijit.form.Button");
- </script>
- <script>
- function helloCallback(data,ioArgs) {
- alert(data);
- }
- function helloError(data,ioArgs) {
- alert('Error when retrieving data from the server!');
- }
- </script>
- </head>
- <body class="tundra">
- <button dojoType="dijit.form.Button"id="helloButton">Hello World!
- <script type="dojo/method" event="onClick">
- dojo.xhrGet({
- url: 'response.txt',load: helloCallback,error: helloError
- });
- </script>
- </button>
- </body>
- </head>
helloCallback作为回调函数,异步请求的发送通过dojo.xhrGet完成,helloError处理异常,值得注意的是"dojo.require("dijit.form.Button");",引入了dojo的buttonwidget,并且可直接用于html ui构建中,有点类似于服务器端代码顶端的引用,符合OO程序员的习惯,运行页面,直接点击button就可以看到效果。