In this code :
if (!parms.script) { // no script... load filename
execscript(parms, function (data){
var text={'result':'success', 'response':data };
if(typeof(data)!='object') {
try {
text.response=JSON.parse(text.response);
} catch(e) {
text={'result':'success','response':data};
}
}
responsehttp.end(JSON.stringify(text));
});
} else {
//parameterised input will replace in script
if(query.paraminput!=undefined) {
var paraminput=qs.parse(query.paraminput);
parms=merge_options(parms, paraminput);
}
execscript(parms, function (data){
var text={'result':'success', 'response':data };
if(typeof(data)!='object') {
try {
text.response=JSON.parse(text.response);
} catch(e) {
text={'result':'success','response':data};
}
}
responsehttp.end(JSON.stringify(text));
});
}
in execscript callback it is called two times , i want to make a single function for executing both call back in if and else .
how can i achieve this .
i tried making seperate function but responsehttp undefinded error camed.
The problem is (I suspect) is that you had your common function declared outside the context of your http response handler and, therefore, responsehttp wasn’t defined. Instead create it as a closure function inside your outer function’s scope: