[英]My Jade template button won't submit. Any ideas?
I'm a node noob and am following a tutorial trying to build my first application. 我是节点菜鸟,并且正在按照教程尝试构建我的第一个应用程序。 For some reason my button is not doing anything at all.
由于某种原因,我的按钮根本不执行任何操作。 I'm not even receiving a 404 error (which I presume would mean the post method was working at least).
我什至没有收到404错误(我认为这意味着post方法至少可以正常工作)。
Here is my jade file. 这是我的玉档案。 'newuser.jade'
'newuser.jade'
extends layout
block content
h1= title
form#formAddUser( name="adduser",method="post",action="/adduser")
input#inputUserName(type="text",placeholder="username",name="username")
input#inputUserEmail(type="text",placeholder="useremail",name="useremail")
button#btnSubmit(type="submit") submit
js file: 'index.js' js文件:“ index.js”
/* POST to Add User Service */
router.post('/adduser', function(req, res) {
// Set our internal DB variable
var db = req.db;
// Get our form values. These rely on the "name" attributes
var userName = req.body.username;
var userEmail = req.body.useremail;
// Set our collection
var collection = db.get('usercollection');
// Submit to the DB
collection.insert({
"username" : userName,
"email" : userEmail
}, function (err, doc) {
if (err) {
// If it failed, return error
res.send("There was a problem adding the information to the database.");
}
else {
// And forward to success page
res.redirect("userlist");
}
});
});
You need to increase the indent level after form
, otherwise the inputs and button don't become nested within the <form>...</form>
tags: 您需要在
form
之后增加缩进级别,否则输入和按钮不会嵌套在<form>...</form>
标记内:
form#formAddUser( name="adduser",method="post",action="/adduser")
input#inputUserName(type="text",placeholder="username",name="username")
input#inputUserEmail(type="text",placeholder="useremail",name="useremail")
button#btnSubmit(type="submit") submit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.