Dojo BASICS (3) send data to the server and send data to the server using get and post.
First, replace the html code in the body
Hello World!
Enter the name:
If you do not enter data, how can you submit the data.
- Get
We only need:
Function helloPressed ()
{
Dojo. io. bind ({
Url: 'response.txt ',
Handler: helloCallback
});
}
Replace:
function helloPressed()
{
dojo.io.bind({
url: 'HelloWorldResponseGET.jsp',
handler: helloCallback,
content: {name: dojo.byId('name').value }
});
}
Now, the URL in the example can be clearly described. The example is relative. The example is in the current directory of helloworld.html.
There should be a HelloWorldResponseGET. jsp file. handler is still the same, processing the returned data,
If yes.
Content is the data to be sent. The name and name are the values you enter.
In this way, we can write simple code in jsp to get this value. The following is the code in jsp.
<%
/*
'Helloworldresponseget. jsp
'--------
'
'Print the name value.
'
*/
Response. setContentType ("text/plain ");
%>
Hello <% = request. getParameter ("name") %>. Welcome to the dojo world!
- Post
This method submits data in the form.
The corresponding html code is:
Hello World!
The dojo code is:
function helloPressed()
{
dojo.io.bind({
url: 'HelloWorldResponsePOST.jsp',
handler: helloCallback,
formNode: dojo.byId('myForm')
});
}
Here, the content attribute is changed to the formNode attribute.
The jsp code remains unchanged.
Here, the basics of dojo have come to an end. These contents come from the official website of dojo. For more details, see the official website.
Http://dojo.jot.com/WikiHome/Tutorials/HelloWorld