我想知道从 HTML 表单访问通过 post 方法发送的参数的命令
我已经尝试了所有这些,但它们会打印undefined
或发回error
...
编辑1:忘了提,我也添加了这个server.use(express.bodyParser());
编辑2:
var express = require('express'),
server = express(),
client = require('mysql').createConnection({ host:'localhost', user:'root', password:'password' });
在 MySQL 中使用 dbCRUD 进行休息服务
var dbcrud = require('dbcrud').init(client, 'contacts', model);
然后我做一个
server.use(express.bodyParser());
发布功能在这里执行..
server.post('/families',function(req,res){
console.log(req.id);
console.log("1: " + req.param.id);
console.log("2: " + req.params.id);
console.log("3: " + req.param("id"));
console.log("4: " + req.params('id'));
console.log("5: " + req.params[0]);
console.log("6: " + req.body.name);
console.log("7: " + req.body.notes);
console.log("8: " + req.body.id);
//console.log("5: " + req.params[0]);
res.send('Hello POST : families');
});
我在这里添加路线...
dbcrud.addRoutes(server);
在 HTML 表单中,我为输入标签指定了 id 和 name 属性...
<form method="post" action="http://10.180.218.72:3000/families">
id : <input type="number" id="id" name="id"></input>
name : <input type="text" id="name" name="name"></input>
notes : <input type="text" id="notes" name="notes"></input>
<input type="submit" value = "submit" ></input>
</form>