简体   繁体   English

如何使用node.js express框架将html表单的值从一页提交到另一页

[英]how to submit values of html form from one page to another using node.js express framework

am using node.js express framework and m totally new in this environmentnd m stuck in a problem which is i have to submit my html form values to the next page using node.i have three folder there one controller 2nd views and third is public.. here is my html form 我正在使用node.js表达框架,并且在此环境中是全新的,陷入了一个问题,即我必须使用node.html将我的html表单值提交到下一页。我有三个文件夹,一个控制器是第二个视图,第三个是公共的。这是我的html表格

<form action="/myaction" method="post">
        <fieldset>
            <label for="name">Name:</label>
            <input type="text" id="name" name="name" placeholder="Enter your full name" />
            <label for="email">Email:</label>
            <input type="email" id="email" placeholder="Enter your email address" />
            <label for="message">Message:</label>
            <textarea id="message" placeholder="What's on your mind?"></textarea>
            <input type="submit" value="Send message" />
        </fieldset>
    </form>

and here is my app.js 这是我的app.js

var express = require('express');
var http = require('http');
var cons=require('consolidate');
var path = require('path');
var bodyParser= require('body-parser');
var methodOverride = require('method-override');
var Controllerdefault = require('./controllers/default');
var app = express();
app.engine('html',cons.swig);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
var hour = 3600000;
var day = hour*24;
var week = day * 7;
app.use(express.static(path.join(__dirname,'public'),
{
maxAge:week}));
app.use(express.bodyParser());
app.post('/myaction', function(req, res) {
  res.send('You sent the name "' + req.body.name + '".');
});
app.get('/' , Controllerdefault.index );
app.get('/home' , Controllerdefault.index2);
app.get('/new' , Controllerdefault.index3);
console.log('Express app started on port 3000');
app.listen(3000);

any body tell me how can i submit values because i do it but error come in cmd is like that.. 任何机构都告诉我如何提交值,因为我这样做了,但是cmd中出现错误就是这样。

Error: Most middleware (like bodyParser) is no longer bundled with Express and m
ust be installed separately. Please see https://github.com/senchalabs/connect#mi
ddleware.
    at Function.Object.defineProperty.get (C:\Users\Tahir\Desktop\node_modules\e
xpress\lib\express.js:89:13)
    at Object.<anonymous> (C:\Users\Tahir\Desktop\firstapp\app.js:20:17)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

You should install body-parser separately, because you are using Express 4. npm install body-parser and then use it 您应该单独安装body-parser,因为您使用的是npm install body-parser ,然后再使用它

                   var bodyParser = require('body-parser');

for more details see https://github.com/expressjs/body-parser 有关更多详细信息,请参见https://github.com/expressjs/body-parser

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Node.js Express框架自动绑定HTML表单中的集合? - How to auto bind collection from HTML form using node.js express framework? 如何通过 onclick 和 node.js 将数据从一页传递到另一页并表达? - How to pass data from one page to another by onclick with node.js and express? 如何在不使用Ajax /使用express的情况下从html页面运行node.js函数? - How do I run a node.js function from an html page without using ajax/using express? 使用 Express 和表单输入提交在 Node.js 上执行查询 - Execute Query on Node.js Using Express and Form Input Submit 如何使用 Express 和 Node.js 从表单发送参数 - How to send parameters from a form using Express and Node.js 如何在Node.Js + Express + Jade中提交复杂的表单? - How to submit complex form in Node.Js + Express + Jade? 如何使用React / Node.js / Express框架异步提交POST请求? - How to asynchronously submit POST request using React/Node.js/Express framework? 如何在node.js中将控件从一个html页面更改为另一个? - how to change control from one html page to another in node.js? 如何使用HTML表单发送电子邮件并使用Node.js和Gulp提交电子邮件? - How to send an e-mail using an HTML form and submit it using Node.js and Gulp? 如何使用node.js中的express框架提供图像文件? - How to serve the image files using express framework in node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM