【发布时间】:2021-07-28 02:25:02
【问题描述】:
我有一个函数,在发出post 请求后,必须进行get api 调用。我尝试通过从帖子中调用一个函数来实现这一点。
app.post('/',function(req,res){
res.send(req.body);
callGet(req.body)
})
function callGet(value){ // value updated after every call
app.get('/val',function(req,res){
getVal(value); // value doesn't update after first call
function getVal(value){
#do something
}
res.send(resultFrom_getVal)
})
}
从post 传递的参数在每次调用后都会在callGet(value) 中更新,但不会在第一次调用后反映在getVal(value) 中。因此,在每篇文章之后,它都会呈现第一个 post 调用参数。如果我的实现方式错误,请纠正我,我是使用 REST api 的新手。
【问题讨论】: