Home > Web Front-end > JS Tutorial > body text

Basics of dojo (3) Sending data to the server_dojo

WBOY
Release: 2016-05-16 19:16:18
Original
1090 people have browsed it

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">
Copy after login
How to submit data without entering data?
  1. get
    We only need to change:
    <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>   }
    Copy after login
    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
    . The handler is still the same, processing the returned data,
    if any.
    content is the data to be sent. The name is name, and the value of name is The value you entered.

    In this way, we can write simple code in jsp to obtain this value. The following is the code in jsp

    <%<BR> /*<BR> ' HelloWorldResponseGET.jsp<BR> ' --------<BR> '<BR> ' 打印name的值.<BR> '<BR> */<br><br> response.setContentType("text/plain");<BR>%>
    Copy after login
    Hello <%= request.getParameter("name") %> ,欢迎来到dojo世界!
    Copy after login
  2. Post
    This method is to submit the data in the form. The corresponding html code of

    is:
    <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>
    Copy after login
    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>   }
    Copy after login
    Here the content attribute is changed to the formNode attribute.

    The jsp code remains unchanged.
At this point, the basics of dojo come to an end. These contents are from the official website of dojo. More details Please refer to the official website for the content.
http://dojo.jot.com/WikiHome/Tutorials/HelloWorld
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template