search

Home  >  Q&A  >  body text

javascript - How to pass the value to the page after express calls the interface?

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?

阿神阿神2767 days ago839

reply all(5)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-31 10:38:51

    iconUrl must be undefined.
    It’s a problem with the basic scope of js

    reply
    0
  • ringa_lee

    ringa_lee2017-05-31 10:38:51

    Put the sentence res.render into the req.on('end') callback

    reply
    0
  • 漂亮男人

    漂亮男人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.

    reply
    0
  • phpcn_u1582

    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.

    reply
    0
  • 阿神

    阿神2017-05-31 10:38:51

    Just write it in the end

    reply
    0
  • Cancelreply