Anonymous Js Function With Xhrpost Dojo Not Returning Data
var cType = function(templateId){ dojo.xhrPost({ url : '/mediation1.0.1/template/getCollectorType', handleAs : 'text', headers : {'Conte
Solution 1:
The problem is that your cType function does not return anything.
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.
};
You should be using dojo.Deferred
to accomplish what you are trying to do:
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 (This has an example that shows the deferred technique)
http://dojotoolkit.org/reference-guide/1.7/dojo/xhrPost.html
Post a Comment for "Anonymous Js Function With Xhrpost Dojo Not Returning Data"