Ok, having an issue withe the return value of a function always returning “undefined”
Heres my code:
//called here:
var res = comms(GENSET_SN);
//the function
function comms(genserial) {
var Result;
//Webservice called here
MyServices.getCommsState(genserial, "S1", OnComplete1);
function OnComplete1(args) {
var Res = eval("(" + args + ")");
if (Res == 1) {
Result = 1;
} else {
Result = 0;
}
}
return Result;
}
please help!!
I’m guessing
MyServices.getCommsState(genserial, "S1", OnComplete1);is an ajax request?If so, the value of
Resultwill be returned before it is actually set in theOnComplete1callback, henceundefined.You will need to pass in a callback function containing the code that will use the
Resultvalue.You can change the code to do this instead, note that you pass in the function to comms and then call it in
OnComplete1: