`
xiaotian_ls
  • 浏览: 304399 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

dojo.io.bind使用详解

    博客分类:
  • Ajax
阅读更多
访问一个纯文本资源:
dojo.io.bind({
    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",
    load: function(type, evaldObj){ /* do something */ },
    mimetype: "text/javas cript"
});

提交Form:

dojo.io.bind({
    url: "http://foo.bar.com/processForm.cgi",
    load: function(type, evaldObj){ /* do something */ },
    formNode: dojo.byId("formToSubmit")
});

参数:
加载一段
url:
the location of the resource being requested
mimetype:
Mimetype used to interpret the contents of the response with. Defaults to "text/plain". This does not set an outgoing mime header for HTTP transports.
method:
Format to use whem making the request. For HTTP transports this us usually either of "GET" or "POST" although non-HTTP transports may define and accept others. Defaults to "GET".
content:
An key/value mapping of properties to be constructed into paramaters passed with the data request. In HTTP transports, these are equivalent to query string paramaters or form fields in POST requests. The exact behavior of content-specified paramaters is dependent upon the transport in use. the value format should like {key1:value1,key2:value2}
load:
                         成功回调函数
error:
                         错误回调函数

transport:
String that explicitly specifies the transport object to use for the request. If the specified transport is not available, the request will not be made and the error callback will be fired.
changeUrl:
Boolean, defaults to false. Determines whether or not the request should be made "bookmarkable". This may be removed in the future as it pertains exclusively to in-browser HTTP transports.
formNode:
DOM Node that specifies a form to be serialized and submitted by this request. Form nodes may be used to populate the method and url properties by some transports. This property may be removed in the future as it pertains exclusively to in-browser HTTP transports.
sync:
Boolean, defaults to false. sync determines whether the accepting transport should attempt to make the request synchronously. Transports that support synchronous operation will block execution of other code until the bind is complete.
bindSuccess:
Boolean, defaults to false. Indicates whether or not this Request was accepted and dispatched by any transport.
useCache:
Boolean, defaults to false. Indicates whether the result of the request should be cached and whether requesting a result for this request from the cache is acceptable.
timeout:
                         请求超时时间

 

原文: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, data, evt){ /*do something w/ the data */ }, mimetype: "text/plain"});

以上的代码即全部的实现。通过代码我们已经提供了获取数据的地址,获取了数据后的回调函数。不过,当请求出错时,我们需要提供错误处理函数:

 

dojo.io.bind({ 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"});

当然,只注册单一的处理函数也是可以的,在这个处理函数中需要指明传递的事件类型进行相应的处理,用这种方式取代对load和error处理函数的分别注册:

 

dojo.io.bind({ url: "http://foo.bar.com/sampleData.txt", handle: function(type, data, 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", load: function(type, evaldObj){ /* do something */ }, mimetype: "text/java script"});

当然,如果我们希望确保使用的是XMLHttpRequest传输对象,可以采用如下方式指定:

 

dojo.io.bind({ url: "http://foo.bar.com/sampleData.js", load: function(type, evaldObj){ /* do something */ }, mimetype: "text/plain", // get plain text, don't eval() transport: "XMLHTTPTransport"});

除了以上提供的全面的功能外,bind()方法同时还支持通过请求的方式提交表单(注意:这里不支持通过XMLHTTP上传文件):

 

dojo.io.bind({ url: "http://foo.bar.com/processForm.cgi", load: function(type, evaldObj){ /* do something */ }, formNode: document.getElementById("formToSubmit")});

 

原文:http://blog.csdn.net/pian_yun/archive/2007/09/18/1790525.aspx

分享到:
评论

相关推荐

    dojo.js 1.4.2

    dojo.js 1.4.2dojo.js 1.4.2dojo.js 1.4.2dojo.js 1.4.2dojo.js 1.4.2dojo.js 1.4.2dojo.js 1.4.2

    dojo.js.uncompressed.js 1.4.2

    dojo.js.uncompressed.js 1.4.2dojo.js.uncompressed.js 1.4.2dojo.js.uncompressed.js 1.4.2

    Dojo.js核心dojo的javaScript类库Dojo.js核心dojo的javaScript类库Dojo.js核心dojo的javaScript类库

    dojo.js.核心jsDojo.js核心dojo的javaScript类库Dojo.js核心dojo的javaScript类库Dojo.js核心dojo的javaScript类库Dojo.js核心dojo的javaScript类库

    dojo.zip

    它提供了一系列的函数,如`dojo.xhrGet`、`dojo.xhrPost`等,用于向服务器发送异步请求,获取或发送数据,从而实现页面无刷新的数据交互。 3. **dojo的模块系统**:dojo的基础是它的模块系统,它使用了AMD规范来...

    dojo精品中文教程(包一)

    dojo学习笔记(一)-dojo.io.IO & dojo.io.BrowserIO) dojo学习笔记(三) dojo学习笔记(二) dojo.lang.array & dojo.lang.func & dojo.string.extras dojo学习笔记(六)- ContentPane dojo学习笔记(四)...

    DOJO.js 最优秀的js 框架 1.9.3

    **DOJO.js 框架详解** DOJO.js 是一个功能强大的JavaScript库,它被誉为“最优秀的js框架”之一,特别是在版本1.9.3中,这个称号得到了充分的体现。DOJO以其全面的特性、模块化的设计以及对各种浏览器的良好支持而...

    dojo精品中文教程(包二)

    dojo学习笔记(一)-dojo.io.IO & dojo.io.BrowserIO) dojo学习笔记(三) dojo学习笔记(二) dojo.lang.array & dojo.lang.func & dojo.string.extras dojo学习笔记(六)- ContentPane dojo学习笔记(四)...

    dojo精品中文教程(全)

    dojo学习笔记(一)-dojo.io.IO & dojo.io.BrowserIO) dojo学习笔记(三) dojo学习笔记(二) dojo.lang.array & dojo.lang.func & dojo.string.extras dojo学习笔记(六)- ContentPane dojo学习笔记(四)...

    dojo.xd.js

    dojo.xd.js 最新JavaScript框架组件!

    dojo-0.3.1-ajax

    8. **dojo.io.bind** 在Dojo 0.3.1中,`dojo.io.bind`是一个更底层的AJAX接口,它可以处理更多的细节,如自定义请求头、超时和自定义HTTP方法。不过,它不如xhr系列方法常用,因为后者的API更简洁。 9. **dojo....

    资源名称dojo.js

    dojo.js

    Pragmatic.Bookshelf.Mastering.Dojo.Jun.2008.pdf

    书中详细讲解了如何使用dojo.require和dojo.provide,以及如何使用dojo.moduleUrl来定位模块资源。 3. **数据绑定和模板**:Dojo提供了dijit.form组件和dojox.data服务,用于实现视图和模型之间的数据绑定。同时,...

    dojo精品中文教程(包三)

    dojo学习笔记(一)-dojo.io.IO & dojo.io.BrowserIO) dojo学习笔记(三) dojo学习笔记(二) dojo.lang.array & dojo.lang.func & dojo.string.extras dojo学习笔记(六)- ContentPane dojo学习笔记(四)...

    dojo.js 1.92版

    dojo.js.uncompressed.js 1.92版

    Dojo.GUI_v6.zip for pencil

    使用【Dojo.GUI_v6.zip for pencil】,设计师可以创建出高度真实的Dojo风格的Web原型,不仅展示了UI组件的功能,还能够模拟用户与界面的交互。这种模板特别适合那些熟悉或计划使用Dojo Toolkit开发Web应用的团队,...

    dojo学习...........

    - AJAX通信:Dojo的IO模块支持异步数据请求,如`dojo.io.*`,便于与服务器进行数据交互。 - UI组件:`dojo.widget.*`包含了多种可复用的UI组件,如按钮、表单元素等,方便快速构建用户界面。 - 动画效果:Dojo的动画...

    domino xapges 其中的dojo.xhrGet 和 dojo.xhrPost例子

    domino xapges 其中的dojo.xhrGet 和 dojo.xhrPost例子

    DOJO 学习笔记 dojo

    `dojo.io.IO` 和 `dojo.io.BrowserIO` 是处理 I/O 任务的关键模块,包括发送 AJAX 请求和处理服务器响应。`dojo.dom` 模块则提供了操作 DOM(文档对象模型)节点的方法,如查找、创建、修改和删除元素。 `dojo....

    dojo.js javasrcpt

    难得纯净资源,不用下载其他乱起八糟的东西了

Global site tag (gtag.js) - Google Analytics