Home >Web Front-end >JS Tutorial >Basics of dojo (3) Sending data to the server_dojo
There are two ways to send data to the server: get and post.
First, replace the html code in the body with
<pre class="brush:php;toolbar:false"> <button dojoType="Button" widgetId="helloButton">Hello World!</button><br> <br><br> 请输入名称: <input type="text" id="name">How to submit data without entering data?
<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> }in the basic part (2). Needless to say, you can understand the url in it. It is a relative path. That is to say, in the current location of HelloWorld.html There should be a HelloWorldResponseGET.jsp file under the directory
<%<BR> /*<BR> ' HelloWorldResponseGET.jsp<BR> ' --------<BR> '<BR> ' 打印name的值.<BR> '<BR> */<br><br> response.setContentType("text/plain");<BR>%>
Hello <%= request.getParameter("name") %> ,欢迎来到dojo世界!
<pre class="brush:php;toolbar:false"> <button dojoType="Button" widgetId="helloButton">Hello World!</button><br> <br><br> <form id="myForm" method="POST"><br> 请输入名称: <input type="text" name="name"><br> </form>dojo code is:
<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> }Here the content attribute is changed to the formNode attribute.
http://dojo.jot.com/WikiHome/Tutorials/HelloWorld