【问题标题】:Get data from express to form in html从express中获取数据到html中的表单
【发布时间】:2021-08-15 12:12:44
【问题描述】:

有一个小而简单的例子。 我想检查数据是否在服务器中(例如该人是否已签名)。如果它在服务器中,我知道我可以在 express 中 res.redirect 继续前进,但如果没有,我如何从 html 中的服务器获取响应,而不是使用 angular 左右,例如 pop如果他在数据库中未被识别,则发送一条消息。

<form action="/IsSIgn" method="POST">
<input type="text" name="name">
<button type="submit">sign in</button>
</form>

【问题讨论】:

    标签: html angular express


    【解决方案1】:

    解决方案 1:

    res.send("<script>window.alert('unauthorized');</script>")
    
      
    res.send("<script>window.alert('unauthorized');window.location.href='/example-page-route'</script>")
    

    解决方案 2:

    为无效名称创建另一个 html 页面 并重定向到该页面

    【讨论】:

    • 在 html 中哪里可以收到这些数据?
    • 而且弹出后页面是空白的
    • 对于您必须实现 fetch 方法或 ajax 请求的数据。弹出后,您可以重新加载窗口或再次重定向到登录页面。为此,您必须使用 window.location.href 并重新加载 window.location.reload(),正如我在解决方案中提到的那样
    猜你喜欢
    • 2012-05-17
    • 2012-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 2013-01-08
    相关资源
    最近更新 更多