页面没有通过Express使用post(NodeJS) [英] Page not getting rendered via Express when using post (NodeJS)

查看:371
本文介绍了页面没有通过Express使用post(NodeJS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Express v.2.4.6(Node.js - v.0.6.2)。
一旦POST被调用(而不是GET),我试图渲染(或重定向到)一个新页面。当GET被调用时,我能够渲染/重定向。但是,在Express中调用POST时,我似乎无法呈现页面。我不知道这是否可能,尽管快速网站的指南确实提到一个例子,您可以在POST调用后重定向。
相关代码如下(客户端以JSON形式发送表单)。我可以在Node.j中成功解析JSON消息。

I am using Express v.2.4.6 (Node.js - v.0.6.2). I am trying to render (or redirect to) a new page once POST is called (as opposed to GET). I am able to render/redirect when GET is called. However, I cannot seem to render a page when POST is called in Express. I am not sure if this is even possible though the guide on the Express site does mention an example where you can redirect once POST is called. The relevant code is given below (client is sending the form in JSON). I can parse through the JSON message successfully in Node.j.

路由示例:

app.post('/signup', function(req, res){
res.redirect('index');
//res.render('index');
});

不会抛出异常,但索引页不会被渲染或重定向。
任何反馈将不胜感激。

No exceptions are thrown, but the index page does not get rendered nor redirected. Any feedback will be appreciated.

推荐答案

res.redirect('/')很可能是你想要的,但是你可以在任何路线上呈现,重定向只是大多数人使用

res.redirect('/') is most likely what you wanted there, but you can render in any route, redirecting is just a convention that most people use

这篇关于页面没有通过Express使用post(NodeJS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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