【问题标题】:Express - How do I pass data to the model without using query string parametersExpress - 如何在不使用查询字符串参数的情况下将数据传递给模型
【发布时间】:2018-03-27 20:57:22
【问题描述】:

所以,我有两个控制器,authControlleronboardingController。 authController 通过以下代码与 onboardingController 通信:

res.redirect('/onboarding/info?profileId=' + profile.id + '&emailAddress=' + profile.emails[0].value)

onBoardingController 接收查询字符串参数并将其转换为渲染相应页面时可访问的元数据:

model.profile = { id: req.query.profileId, email: req.query.emailAddress };
res.render('onboarding/missingInfo', model);

现在,由于 onboardingController 中的 model.profile 不知道来自 authController 的实际配置文件数据背后的上下文,我只想通过查询字符串传递和接收数据。有没有其他方法可以做到这一点,因为 URL 中包含电子邮件地址会使它看起来很奇怪。

编辑:我读到可以使用快速会话来做我需要的事情。

【问题讨论】:

    标签: javascript express query-string


    【解决方案1】:

    您可以创建一个 POST 请求并在请求正文中发送它(使用 axios 或 Fetch API)。

    Nice article of W3Schools about it

    【讨论】:

      猜你喜欢
      • 2013-01-18
      • 1970-01-01
      • 2012-06-09
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      相关资源
      最近更新 更多