Home >Web Front-end >JS Tutorial >Basics of dojo (2) Reading data from the server_dojo

Basics of dojo (2) Reading data from the server_dojo

WBOY
WBOYOriginal
2016-05-16 19:16:201157browse

This example follows the content in "Basics of Dojo"
First, we create a new file in the same directory as HelloWorld.html, named response.txt,内容为:<br><br>Welcome to the Dojo Hello World Tutorial

Replace the code in section 2 with the following code

<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>必需</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>
The above is all the code.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn