问题是您的 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