url: "http://foo.bar.com/sampleData.txt",
load: function(type,data,evt){ /*do something w/ the data */ },
error: function(type,error){ /*do something w/ the error*/ },
mimetype: "text/plain"
});
dojo.io.bind({
url: "http://foo.bar.com/sampleData.js",evaldObj){ /* do something */ },
mimetype: "text/javas cript"
});
提交Form:
dojo.io.bind({
url: "http://foo.bar.com/processForm.cgi",
formNode: dojo.byId("formToSubmit")
});
参数: 加载一段
成功回调函数
error:
错误回调函数
transport:
请求超时时间
原文:http://blog.chinaunix.net/u/8780/showart_349663.html
dojo.io包的大多数魔力通过bind()展现。dojo.io.bind() 提供了通用的异步请求API。
我们可以使用以下的代码从一个URL地址中请求获取原始文本:
dojo.io.bind({ url: "http://foo.bar.com/sampleData.txt",load: function(type,mimetype: "text/plain"});
以上的代码即全部的实现。通过代码我们已经提供了获取数据的地址,获取了数据后的回调函数。不过,当请求出错时,我们需要提供错误处理函数:
dojo.io.bind({ url: "http://foo.bar.com/sampleData.txt",error: function(type,mimetype: "text/plain"});
当然,只注册单一的处理函数也是可以的,在这个处理函数中需要指明传递的事件类型进行相应的处理,用这种方式取代对load和error处理函数的分别注册:
dojo.io.bind({ url: "http://foo.bar.com/sampleData.txt",handle: function(type,evt){ if(type == "load"){ // do something with the data object }else if(type == "error"){ // here,"data" is our error object // respond to the error here }else{ // other types of events might get passed,handle them here } },mimetype: "text/plain"});
出于性能的考虑,我们经常使用的一种动态加载内容的做法是请求java script语法的字符串,然后进行eval操作。bind方法也同时包含了这种处理操作,我们只需要设置mimetype参数,提供希望获取的响应类型:
dojo.io.bind({ url: "http://foo.bar.com/sampleData.js",mimetype: "text/java script"});
当然,如果我们希望确保使用的是XMLHttpRequest传输对象,可以采用如下方式指定:
dojo.io.bind({ url: "http://foo.bar.com/sampleData.js",mimetype: "text/plain",// get plain text,don't eval() transport: "XMLHTTPTransport"});
除了以上提供的全面的功能外,bind()方法同时还支持通过请求的方式提交表单(注意:这里不支持通过XMLHTTP上传文件):
dojo.io.bind({ url: "http://foo.bar.com/processForm.cgi",formNode: document.getElementById("formToSubmit")});
原文:http://blog.163.com/yangtao_0329/blog/static/2359758920073410025211/版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。