dojo Quick Start/dojo入门手册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/soundcode/p/2117552.html