dojo 之基礎(chǔ)篇(二)之從服務(wù)器讀取數(shù)據(jù)
更新時間:2007年03月24日 00:00:00 作者:
本例子沿用 "dojo 之基礎(chǔ)篇" 中的內(nèi)容
首先,我們在HelloWorld.html的同一級目錄,新建一個文件,名為
將section 2的代碼替換 為以下代碼
首先,我們在HelloWorld.html的同一級目錄,新建一個文件,名為
response.txt,內(nèi)容為:
Welcome to the Dojo Hello World Tutorial將section 2的代碼替換 為以下代碼
以上為所有代碼.<!-- SECTION 3 -->
<script type="text/javascript">
dojo.require("dojo.io.*");
dojo.require("dojo.event.*");
dojo.require("dojo.widget.*");
dojo.require("dojo.widget.Button");
//綁定url路徑. 當(dāng)然按下按鈕后, 會向response.txt發(fā)送請求,此時,服務(wù)器
//將返回response.txt中的內(nèi)容.這個url可以是其它的對象.比如struts中的
//***.do 或者 是一個servlet url.
function helloPressed()
{
dojo.io.bind({
url: 'response.txt',
handler: helloCallback
});
}
//處理返回?cái)?shù)據(jù)的函數(shù). 其三個參數(shù)是必需的.
function helloCallback(type, data, evt)
{
if (type == 'error')
alert('Error when retrieving data from the server!');
else
alert(data);
}
function init()
{
var helloButton = dojo.widget.byId('helloButton');
dojo.event.connect(helloButton, 'onClick', 'helloPressed')
}
dojo.addOnLoad(init);
</script>
相關(guān)文章
Dojo之路:如何利用Dojo實(shí)現(xiàn)Drag and Drop效果
Dojo之路:如何利用Dojo實(shí)現(xiàn)Drag and Drop效果...2007-04-04dojo 之基礎(chǔ)篇(二)之從服務(wù)器讀取數(shù)據(jù)
dojo 之基礎(chǔ)篇(二)之從服務(wù)器讀取數(shù)據(jù)...2007-03-03dojo 之基礎(chǔ)篇(三)之向服務(wù)器發(fā)送數(shù)據(jù)
dojo 之基礎(chǔ)篇(三)之向服務(wù)器發(fā)送數(shù)據(jù)...2007-03-03Dojo 學(xué)習(xí)筆記入門篇 First Dojo Example
Dojo學(xué)習(xí)筆記入門篇,第一個小例子, 剛開始學(xué)習(xí)dojo的朋友可以參考下。2009-11-11dojo學(xué)習(xí)第一天 Tab選項(xiàng)卡 實(shí)現(xiàn)
可能很多人都對dojo只聞其名,覺得有了jquery、prototype、YUI等這些優(yōu)秀的js庫了,dojo還有它存在的必要嗎?2011-08-08