简体   繁体   English

返回后如何在javascript函数中获取http响应

[英]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.

相关问题 从HTTP响应中返回的字符串化javascript函数中检索json - Retrieving json from stringified javascript function returned in http response 如何使用javascript打印http响应中返回的内容 - How to print content that is returned in http response using javascript 在 function 中返回来自 promise 的响应后,如何将 go 降到底线? - How can I make it go down to the bottom lines after the response from the promise is returned in the function? 如何在HTTP响应中调用JavaScript函数? - How to call a JavaScript function in the HTTP response? 如何使用jQuery或JavaScript获取HTTP响应 - How to get http response using jquery or javascript 如何获取函数javascript的返回值 - How to get returned value of function javascript 如何使用$ http响应控制器获取服务功能 - how to get service function with $http response to controller 如何执行JavaScript函数从Ajax响应返回 - how to execute a javascript function returned from ajax response 如何从包含jQuery.get()的JavaScript函数中获取返回值? - How can I get returned value from JavaScript function that contain jQuery.get()? Angular 2:如何在从subscribe http.post获得响应后调用函数 - Angular 2: How to call a function after get a response from subscribe http.post
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM