As shown in the picture, I used http.get to request the interface and got the returned data. I now want to transfer the avatar to the index page, but after the http.get method is used, iconUrl is undefined. How can I transfer the data returned from the interface to the index page?
曾经蜡笔没有小新2017-05-31 10:38:51
iconUrl must be undefined.
It’s a problem with the basic scope of js
漂亮男人2017-05-31 10:38:51
Scope issue.
Because your variable iconUrl is declared in req.on, when res.render is called, the iconUrl variable in req.on cannot be found. Try putting the declaration of iconUrl in router.get.
phpcn_u15822017-05-31 10:38:51
Change http.get to a synchronous method or use res.render in the callback. Be careful not to have the same parameter name, just change the alias.