手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >dojo 之基础篇(二)之从服务器读取数据
dojo 之基础篇(二)之从服务器读取数据
摘要:本例子沿用"dojo之基础篇"中的内容首先,我们在HelloWorld.html的同一级目录,新建一个文件,名为response.txt,内...

本例子沿用 "dojo 之基础篇" 中的内容

首先,我们在HelloWorld.html的同一级目录,新建一个文件,名为response.txt,内容为:

Welcome to the Dojo Hello World Tutorial

将section 2的代码替换 为以下代码

<>

<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 之基础篇(二)之从服务器读取数据】相关文章:

JavaScript代码因逗号不规范导致IE不兼容的问题

JS或jQuery获取ASP.NET服务器控件ID的方法

如何取得中文输入的真实长度?

jquery预加载图片的方法

浅析Javascript匿名函数与自执行函数

Ctrl + Enter提交前检测的代码

html代码调试脚本

JQuery勾选指定name的复选框集合并显示的方法

javascript基础知识分享之类与函数化

一些有关检查数据的JS代码

精品推荐
分类导航