Heim  >  Artikel  >  Web-Frontend  >  dojo 之基础篇(三)之向服务器发送数据_dojo

dojo 之基础篇(三)之向服务器发送数据_dojo

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

向服务器发送数据有get和post两种.

首先,要将body中的html代码替换为

<pre class="brush:php;toolbar:false">  <button dojotype="Button" widgetid="helloButton">Hello World!</button><br>  <br><br>  请输入名称: <input type="text" id="name">
不输入数据,怎么提交数据呢.
  1. get
    我们只要将基础篇(二)中的:
    <pre class="brush:php;toolbar:false">   function helloPressed()<br>   {<br>    dojo.io.bind({<br>            url: 'response.txt',<br>            handler: helloCallback<br>          });<br>   }<br>替换为:<br><pre class="brush:php;toolbar:false">   function helloPressed()<br>   {<br>    dojo.io.bind({<br>            url: 'HelloWorldResponseGET.jsp',<br>            handler: helloCallback,<br>            content: {name: dojo.byId('name').value }<br>          });<br>   }
    即可.其中的url不用说也明白了吧.是相对路径.也就是说在HelloWorld.html的当前目录
    下应该有一个 HelloWorldResponseGET.jsp 文件. handler还是一样,处理返回的数据,
    如果有的话.
    content即为要发送的数据. 其中名称为name,name的值为你所输入的值.

    这样,我们可以在jsp中写入简单的代码来获得这个值,以下为jsp中的代码

     /*<br> ' HelloWorldResponseGET.jsp<br> ' --------<br> '<br> ' 打印name的值.<br> '<br> */<br><br> response.setContentType("text/plain");<br>%>
    Hello  ,欢迎来到dojo世界!
  2. Post
    这种方法即为在form表单提交提交数据.

    相应的html代码为:
    <pre class="brush:php;toolbar:false">  <button dojotype="Button" widgetid="helloButton">Hello World!</button><br>  <br><br>  

    请输入名称:
    dojo代码为:
    <pre class="brush:php;toolbar:false">   function helloPressed()<br>   {<br>    dojo.io.bind({<br>            url: 'HelloWorldResponsePOST.jsp',<br>            handler: helloCallback,<br>            formNode: dojo.byId('myForm')<br>          });<br><br>   }
    这里将content属性变为了formNode属性.

    jsp的代码不变.
到此,dojo的基础篇告一段落. 这些内容来自dojo的官方网站. 更详细的内容请参考官网.
http://dojo.jot.com/WikiHome/Tutorials/HelloWorld
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