问题是您的 cType 函数不返回任何内容。
var cType = function(templateId){
dojo.xhrPost({
url : "/mediation1.0.1/template/getCollectorType",
handleAs : "text",
headers : {"Content-Type":"text/html"},
postData : templateId,
load: function(data){
return data;
// this returns from the the load
// function, not the cType function!
}});
// You are not returning anything from the cType function.
};
您应该使用dojo.Deferred
来完成您正在尝试做的事情:
var cType = function(templateId){
var xhrArgs = {
url : "/mediation1.0.1/template/getCollectorType",
handleAs : "text",
headers : {"Content-Type":"text/html"},
postData : templateId
};
return dojo.xhrGet(xhrArgs);
};
var deferred = cType('templateId');
deferred.then(
function(data){
// do something with the data...
},
function(error){
// handle an error calling the server...
}
);
http://dojotoolkit.org/reference-guide/1.7/dojo/xhrGet.html(这有一个显示延迟技术的例子)
http://dojotoolkit.org/reference-guide/1.7/dojo/xhrPost.html