dojo 之基礎(chǔ)篇(三)之向服務(wù)器發(fā)送數(shù)據(jù)
更新時(shí)間: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>
請(qǐng)輸入名稱: <input type="text" id="name">
- get
我們只要將基礎(chǔ)篇(二)中的:function helloPressed()
{
dojo.io.bind({
url: 'response.txt',
handler: helloCallback
});
}
替換為:function helloPressed()
即可.其中的url不用說(shuō)也明白了吧.是相對(duì)路徑.也就是說(shuō)在HelloWorld.html的當(dāng)前目錄
{
dojo.io.bind({
url: 'HelloWorldResponseGET.jsp',
handler: helloCallback,
content: {name: dojo.byId('name').value }
});
}
下應(yīng)該有一個(gè) HelloWorldResponseGET.jsp 文件. handler還是一樣,處理返回的數(shù)據(jù),
如果有的話.
content即為要發(fā)送的數(shù)據(jù). 其中名稱為name,name的值為你所輸入的值.
這樣,我們可以在jsp中寫入簡(jiǎn)單的代碼來(lái)獲得這個(gè)值,以下為jsp中的代碼<%
/*
' HelloWorldResponseGET.jsp
' --------
'
' 打印name的值.
'
*/
response.setContentType("text/plain");
%>Hello <%= request.getParameter("name") %> ,歡迎來(lái)到dojo世界! - Post
這種方法即為在form表單提交提交數(shù)據(jù).
相應(yīng)的html代碼為:
dojo代碼為:<button dojoType="Button" widgetId="helloButton">Hello World!</button>
<br>
<form id="myForm" method="POST">
請(qǐng)輸入名稱: <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學(xué)習(xí)第一天 Tab選項(xiàng)卡 實(shí)現(xiàn)
可能很多人都對(duì)dojo只聞其名,覺得有了jquery、prototype、YUI等這些優(yōu)秀的js庫(kù)了,dojo還有它存在的必要嗎?2011-08-08
dojo 之基礎(chǔ)篇(二)之從服務(wù)器讀取數(shù)據(jù)
dojo 之基礎(chǔ)篇(二)之從服務(wù)器讀取數(shù)據(jù)...2007-03-03
dojo 之基礎(chǔ)篇(三)之向服務(wù)器發(fā)送數(shù)據(jù)
dojo 之基礎(chǔ)篇(三)之向服務(wù)器發(fā)送數(shù)據(jù)...2007-03-03
Dojo之路:如何利用Dojo實(shí)現(xiàn)Drag and Drop效果
Dojo之路:如何利用Dojo實(shí)現(xiàn)Drag and Drop效果...2007-04-04

