简体   繁体   English

我们如何不使用Ajax将sql查询结果数据返回到node.js中的调用者函数?

[英]how do we return sql query result data to caller function in node.js without using ajax?

I am new for node.js . 我是node.js新手。 I want to return data of function to caller function. 我想将函数的数据返回给调用者函数。 please give me the ways to do it. 请给我办法。 I want to return mysql query result data to caller function how i do it ? 我想将mysql query结果数据返回给调用者函数,我该怎么做? thank you in advance. 先感谢您。 have a good day. 祝你有美好的一天。

You cannot return directly any result of the SQL query or any other asynchronous function. 您不能直接返回SQL查询的任何结果或任何其他异步函数。 Any function that does an synchronous operation in Node.js can either take a callback or return a promise. 在Node.js中执行同步操作的任何函数都可以执行回调或返回诺言。 It cannot return the result of the asynchronous operation to its caller because that result is not available yet at the point when the function returns. 它无法将异步操作的结果返回给其调用方,因为该结果在函数返回时尚不可用。

For more info see those answers: 有关更多信息,请参见以下答案:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM