dojo 之基礎(chǔ)篇(三)之向服務(wù)器發(fā)送數(shù)據(jù)
更新時間:2007年03月24日 00:00:00 作者:
向服務(wù)器發(fā)送數(shù)據(jù)有g(shù)et和post兩種.
首先,要將body中的html代碼替換為
首先,要將body中的html代碼替換為
不輸入數(shù)據(jù),怎么提交數(shù)據(jù)呢.<button dojoType="Button" widgetId="helloButton">Hello World!</button>
<br>
請輸入名稱: <input type="text" id="name">
- get
我們只要將基礎(chǔ)篇(二)中的:function 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 }
});
}
下應(yīng)該有一個 HelloWorldResponseGET.jsp 文件. handler還是一樣,處理返回的數(shù)據(jù),
如果有的話.
content即為要發(fā)送的數(shù)據(jù). 其中名稱為name,name的值為你所輸入的值.
這樣,我們可以在jsp中寫入簡單的代碼來獲得這個值,以下為jsp中的代碼<%
/*
' HelloWorldResponseGET.jsp
' --------
'
' 打印name的值.
'
*/
response.setContentType("text/plain");
%>Hello <%= request.getParameter("name") %> ,歡迎來到dojo世界!
- Post
這種方法即為在form表單提交提交數(shù)據(jù).
相應(yīng)的html代碼為:
dojo代碼為:<button dojoType="Button" widgetId="helloButton">Hello World!</button>
<br>
<form id="myForm" method="POST">
請輸入名稱: <input type="text" name="name">
</form>
這里將content屬性變?yōu)榱薴ormNode屬性.function helloPressed()
{
dojo.io.bind({
url: 'HelloWorldResponsePOST.jsp',
handler: helloCallback,
formNode: dojo.byId('myForm')
});
}
jsp的代碼不變.
http://dojo.jot.com/WikiHome/Tutorials/HelloWorld
相關(guān)文章
Dojo 學習筆記入門篇 First Dojo Example
Dojo學習筆記入門篇,第一個小例子, 剛開始學習dojo的朋友可以參考下。2009-11-11Dojo之路:如何利用Dojo實現(xiàn)Drag and Drop效果
Dojo之路:如何利用Dojo實現(xiàn)Drag and Drop效果...2007-04-04