Heim  >  Artikel  >  Web-Frontend  >  dojo 之基础篇(二)之从服务器读取数据_dojo

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

WBOY
WBOYOriginal
2016-05-16 19:16:201123Durchsuche

本例子沿用 "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>
以上为所有代码.
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn