获取json、xml的数据类型--dojo Quick Start/dojo入门手册3

json

那要是我想更换获取到的数据类型,比如json?xml?修改handleAs即可,如: handleAs: "json"

dojo.xhrGet({
    url: "http://localhost/hello/sayHello.jsp",
    handleAs: "json",
    load: function(json)
    {
        alert(json.name)
    }
    //...
});

handleAs: "json-comment-filtered" 使用注释符号/**/把json数据包含起来,推荐使用
handleAs: "json-comment-optional" 首先尝试使用json-comment-filtered,如果执行错误,再使用普通的json格式解析
handleAs: "javascript" dojo尝试把服务器返回的数据当作javascript执行,并把结果作为参数传递给load函数
handleAs: "xml" xml对象。注意在Mozilla和IE中的xml是不同的,推荐使用sarissa

至于json和object的转换等,在http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/other-miscellaneous-function/converting-json有一个表格,应该能找到你需要的。

想要直接提交一个表单就这样:

dojo.xhrGet({
    url: "http://localhost/hello/sayHello.jsp",
    form: dojo.byId("form1")
    //...
});


要解决IE下那个臭名昭著的缓存问题,就这样,preventCache会帮你自动生成一个timestamp

dojo.xhrGet({
    url: "http://localhost/hello/sayHello.jsp",
    preventCache: true
    //...
});

转载于:https://www.cnblogs.com/mylem/archive/2009/11/15/1603230.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值