|
首先,我們?cè)贖elloWorld.html的同一級(jí)目錄,新建一個(gè)文件,名為
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)然按下按鈕后, 會(huì)向response.txt發(fā)送請(qǐng)求,此時(shí),服務(wù)器
//將返回response.txt中的內(nèi)容.這個(gè)url可以是其它的對(duì)象.比如struts中的
//***.do 或者 是一個(gè)servlet url.
function helloPressed()
{
dojo.io.bind({
url: 'response.txt',
handler: helloCallback
});
}
//處理返回?cái)?shù)據(jù)的函數(shù). 其三個(gè)參數(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>
JavaScript技術(shù):dojo 之基礎(chǔ)篇(二)之從服務(wù)器讀取數(shù)據(jù),轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。