I have the app.js file on server side and the index.ejs on client side.
I need to call a function from the server side on the index.ejs
and get a feedback on the index.ejs
that the function was executed.
Index.ejs:
function getData(sessionid, numberOrigin){
//console.log(sessionid);
$.ajax({
type: 'POST',
dataType: 'json',
contentType: "application/json",
url: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/data/query',
data: JSON.stringify({ "sessionID": sessionid,
"xxxxxxx":"xxxxxData",
"parameters": { "data": context.data}
}),
success:function(output) {
//console.log(output);
var name = output.result[0].test;
alert(test);
},
error:function(output) {
return '0';
console.log(output);
}
});
};
App.js:
function updateMessage(res, input, response) {
if (context.counter === 2) {
getData(); //function inside index.ejs
// console.log('it's ok'); //it works fine
}
I'm new to node.js. Hopefully someone can help me on this. If have other alternative or best practices for solved this please let me know.