首頁  >  文章  >  web前端  >  dojo 之基础篇(二)之从服务器读取数据_dojo

dojo 之基础篇(二)之从服务器读取数据_dojo

WBOY
WBOY原創
2016-05-16 19:16:201119瀏覽

本例子沿用 "dojo 之基础篇" 中的内容
首先,我们在HelloWorld.html的同一级目录,新建一个文件,名为response.txt,内容为:<br><br>Welcome to the Dojo Hello World Tutorial

将section 2的代码替换 为以下代码

<pre class="brush:php;toolbar:false">  <!-- SECTION 3 --><br>  <script type="text/javascript"><BR>   dojo.require("dojo.io.*");<BR>   dojo.require("dojo.event.*");<BR>   dojo.require("dojo.widget.*");<BR>	 dojo.require("dojo.widget.Button");<br><br>   //绑定url路径. 当然按下按钮后, 会向response.txt发送请求,此时,服务器<BR>   //将返回response.txt中的内容.这个url可以是其它的对象.比如struts中的<BR>   //***.do 或者 是一个servlet url.<BR>   function helloPressed()<BR>   {<BR>    dojo.io.bind({<BR>            url: 'response.txt',<BR>            handler: helloCallback<BR>          });<BR>   }<br><br>   //处理返回数据的函数. 其三个参数是<B>必需的. <BR>   function helloCallback(type, data, evt)<BR>   {<BR>    if (type == 'error')<BR>     alert('Error when retrieving data from the server!');<BR>    else<BR>     alert(data);<BR>   }<br><br>   function init()<BR>   {<BR>    var helloButton = dojo.widget.byId('helloButton');<BR>    dojo.event.connect(helloButton, 'onClick', 'helloPressed')<BR>   }<br><br>   dojo.addOnLoad(init);<BR>  </script>
以上为所有代码.
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn