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

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

(编辑:jimmy 日期: 2025/12/25 浏览: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 之基础篇
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap