Ok, Rory pointed me in the callback direction for my question posted yesterday. I tried several different options, and at least got to the JavaScript variable from undefined
to [object] [object]
, which is posted here to getCallBack.toString()
, which doesn't work either. So My question is, I am trying to use session scope in ColdFusion to pre-assign select values using AJAX async calls. The values are displayed in console correctly, but attempting to assign the value to a JavaScript variable returns [object] [object]
. Can someone review this and tell me what I am doing wrong?
here is the callback function;
function getCallBack(data) {
// console.table(data);
console.log('callback handler: ' + data);
return data;
}
here is the async call;
jgetValue = function(a) {
return $.ajax({
url: "cfc/SessionMgr.cfc",
type: "get",
//async: false,
dataType: "json",
data: {
method: "jgetValue",
variablename: a
},
error: function(msg) {
console.log(msg);
}
});
}
and the variable I am trying to set, either with/without the .toString()
returns the same value;
var sel = jgetValue('ReportsShowAll').done(getCallBack.toString());
so I revisited the code, with Alex's incredibly helpful comment and have rewritten it to this;
function getCallBack(data) {
console.log('callback handler: ' + data);
return data;
}
jgetValue = function(a) {
return $.ajax({
url: "cfc/SessionMgr.cfc",
type: "get",
dataType: "json",
data: {
method: "jgetValue",
variablename: a
},
error: function(msg) {
console.log(msg);
}
});
}
getter = function(a) {
jgetValue(a).done(getCallBack);
}
console.log('getter for ReportsShowAll: ' + getter('ReportsShowAll'));
and the console writes this in the following order, it seems the 'getter' is still finishing before the json call is;
getter for ReportsShowAll: undefined
callback handler: 1
anyone with an intelligent answer why this would happen? any help would be appreciated.