网络编程 
首页 > 网络编程 > 浏览文章

dojo 之基础篇(二)之从服务器读取数据

(编辑:jimmy 日期: 2025/12/28 浏览:3 次 )
本例子沿用 "dojo 之基础篇" 中的内容
首先,我们在HelloWorld.html的同一级目录,新建一个文件,名为response.txt,内容为:

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路径. 当然按下按钮后, 会向response.txt发送请求,此时,服务器
//将返回response.txt中的内容.这个url可以是其它的对象.比如struts中的
//***.do 或者 是一个servlet url.
function helloPressed()
{
dojo.io.bind({
url: 'response.txt',
handler: helloCallback
});
}

//处理返回数据的函数. 其三个参数是必需的.
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>
以上为所有代码.
上一篇:dojo 之基础篇(三)之向服务器发送数据
下一篇:dojo 之基础篇
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap