栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Node.js请求返回行为异常

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Node.js请求返回行为异常

异步,异步,异步。

您不能从该函数返回异步操作的结果。该函数早已在调用异步回调之前返回。因此,唯一消耗您结果的地方

request.post()
是在回调本身内部,并通过从该回调内部调用其他函数并将数据传递给该其他函数来进行。

var oauth = request.post(oauthOptions, function(e, r, body) {    // use the result here    // you cannot return it    // the function has already returned and this callback is being called    // by the networking infrastructure, not by your pre    // you can call your own function here and pass it the async result    // or just insert the pre here that processes the result    processAuth(body);});// this line of pre here is executed BEFORE the callback above is called// so, you cannot use the async result here

仅供参考,对于新的node.js / Javascript开发人员来说,这是一个非常常见的学习问题。要在节点中进行编码,您必须学习如何使用这样的异步回调。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/485111.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号