I am using session scope in ColdFusion and have created an AJAX setter and getter. When I call the jQuery function for the getter I get undefined
, but inside the jQuery call I write to the console and the values are correct. I have tried async: false
in the AJAX to no avail.
I am building a complex cascade of linked select objects and need for them to default back to the last selected values when reloading the cascade. Has anyone encountered this? I have read everything I can find on StackOverflow and have not been able to solve this, see code example below
AJAX types of GET vs POST, AJAX async: false
, sessionManager
and pretty much everything else I found here.
By default session.ReportsShowAll = 1
, but could change, so I use jgetValue()
to get the most recent value and while creating the select, set the selected option to whatever session.ReportsShowAll
currently is. This logic is populated in a variety of areas but I am troubleshooting the one instance to predicate elsewhere.
The AJAX call writes to the console:
jgetValue: ReportsShowAll value: "1"
However the var sel
setting gets undefined
.
jgetValue = function(a) {
$.ajax({
url: "cfc/SessionMgr.cfc",
type: "get",
//async: false,
dataType: "text",
data: {
method: "jgetValue",
variablename: a
},
success: function(response) {
console.log('jgetValue: ' + a + ' value: ' + response);
return response;
},
error: function(msg) {
console.log(msg);
}
});
}
here is the modified callback system written according to the duplicate thread.
getter = function(a) {
var callback = jgetValue(a);
return callback;
}
function getCallBack(response) {
console.log('callback handler: ' + response);
return response;
}
callback handler: "1"
jgetValue = function(a) {
$.ajax({
url: "cfc/SessionMgr.cfc",
type: "get",
//async: false,
dataType: "text",
data: {
method: "jgetValue",
variablename: a
},
success: getCallBack //function(response) {
//console.log('jgetValue: ' + a + ' value: ' + response);
// getCallBack();
//return response;
//}
,
error: function(msg) {
console.log(msg);
}
});
}
both methods, before the async call and after the call still do not set the value to the javascript object, still considers it undefined.
var sel = jgetValue('ReportsShowAll');