提交表单后的节点JS重定向 [英] Node JS redirection after submiting a form

查看:131
本文介绍了提交表单后的节点JS重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的节点应用程序有一个html表单,如果它被提交,它显示/代码和文本,但没有更多,我无法重定向到我的主页。如何将定时器提交到另一个页面后重定向?我尝试在app.post和客户端进行,但它不能正常工作

I have a html form for my node app and if it gets submitted it shows /code and the text but nothing more and i can't redirect to my Mainpage. How can i redirect after it gets submitted with a Timer to another page? I tried to do it in app.post and clientsided but its not working

<form action="/code" method="post" >
<fieldset>
<input type="text"  name="code"  id="code"
style="text-align: center" 
placeholder="Enter Code" /> <br> <br> <input
type="submit" class="btn btn-success" name="submit" id="submit" 
value=" authentifizieren " />
</fieldset>
</form>

App.js

app.post('/code', function(req, res) {


    var code = req.param("code");

    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write('Code: '+code+');
    res.end();
});

我只是想从app.post /代码重定向回我的主页或任何其他网站。

I just want to redirect from app.post /code back to my mainpage or any other website.

推荐答案

重定向在Node JS中:

Redirects in Node JS:

res.writeHead(302, {
  'Location': 'http://example.com/'
});
res.end();

如果你想在客户端做这个,在Node JS中:

If you want to do it client-side, in Node JS:

res.writeHead(200, {'Content-Type': 'text/html'});
res.write('Code: '+code);
res.write('<script>setTimeout(function () { window.location.href = "http://example.com/"; }, 5000);</script>');
res.end();

这篇关于提交表单后的节点JS重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆