不輸入數據,怎么提交數據呢.<button dojoType="Button" widgetId="helloButton">Hello World!</button>
<br>
請輸入名稱: <input type="text" id="name">
Postfunction helloPressed()
{
dojo.io.bind({
url: 'response.txt',
handler: helloCallback
});
}
替換為:function helloPressed()即可.其中的url不用說也明白了吧.是相對路徑.也就是說在HelloWorld.html的當前目錄
{
dojo.io.bind({
url: 'HelloWorldResponseGET.jsp',
handler: helloCallback,
content: {name: dojo.byId('name').value }
});
}
下應該有一個 HelloWorldResponseGET.jsp 文件. handler還是一樣,處理返回的數據,
如果有的話.
content即為要發送的數據. 其中名稱為name,name的值為你所輸入的值.
這樣,我們可以在jsp中寫入簡單的代碼來獲得這個值,以下為jsp中的代碼<%
/*
' HelloWorldResponseGET.jsp
' --------
'
' 打印name的值.
'
*/
response.setContentType("text/plain");
%>Hello <%= request.getParameter("name") %> ,歡迎來到dojo世界!
dojo代碼為:<button dojoType="Button" widgetId="helloButton">Hello World!</button>
<br>
<form id="myForm" method="POST">
請輸入名稱: <input type="text" name="name">
</form>
這里將content屬性變為了formNode屬性.function helloPressed()
{
dojo.io.bind({
url: 'HelloWorldResponsePOST.jsp',
handler: helloCallback,
formNode: dojo.byId('myForm')
});
}
http://dojo.jot.com/WikiHome/Tutorials/HelloWorld
新聞熱點
疑難解答