[英]How can get http response in javascript function after it is returned
I need to call a function passing response rendered to a express-handlebars page. 我需要调用将响应传递给Express-Handlebars页面的函数。 How can I do this? 我怎样才能做到这一点?
This my controller and it is rendering result to a handlebars page. 这是我的控制器,它正在将结果呈现到车把页面。
return servico.obterMetricasStatusCode()
.then((resultado) => {
res.status(200).render('erros', {
resultado: resultado
})
});
At handlebars file I have a div with id "chart_div" where I need to put a google chart so I need to call a function that execute this: 在车把文件中,我有一个id为“ chart_div”的div,需要在其中放置一个Google图表,因此我需要调用一个函数来执行此操作:
var data = google.visualization.arrayToDataTable(resultado);
where the variable called "resultado" is the data to generate the chart but resultado is always undefined when this line is executed. 其中名为“ resultado”的变量是生成图表的数据,但执行此行时resultado始终未定义。
If I put {{resultado}} inside div the object is printed in screen correctly. 如果我将{{resultado}}放在div内,则对象将正确打印在屏幕上。
Can I help me? 我可以帮我吗?
If you are trying to render the returned data, that is accomplished in the view, using your engine. 如果您尝试呈现返回的数据,则可以使用引擎在视图中完成。 if you are just wanting the data returned so that you can manipulate it, I think you want to use res.json(resultado)
or res.send(resultado)
如果您只是想返回数据以便可以操作它,我想您想使用res.json(resultado)
或res.send(resultado)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.