【发布时间】:2016-05-19 18:43:57
【问题描述】:
单击提交按钮,我将数据“名称”重定向到此 url http://localhost:3000/getfileNames.But,现在我正在尝试将数据“名称”获取到同一个 html 页面(http://localhost:3000/login).Can 任何人请帮我解决这……
我的示例.html:
<html>
<head>
</head>
<h1>
Login
</h1>
</head>
<body>
<div id="formContainer">
<form method="post" action="/getfileNames">
Name: <input type="text" name="name" id="name" placeholder="name"> <br><br>
Password: <input type="text" name="pwd" id="pwd" placeholder="password"> <br><br>
<input type="submit" name="submit" value="submit" />
</form>
</div>
</body>
</html>
我的 index.js:
var express = require('express');
var router = express.Router();
router.get("/login", function(req, res)
{
res.sendFile("login.html", {"root": __dirname});
});
router.post('/getfileNames', function(req, res) {
console.log(req.body.name);
res.send('Name: ' + req.body.name);
});
module.exports = router;
【问题讨论】:
-
你能说得更清楚点吗?你是什么意思“重定向数据”? “在登录页面上获取数据”是什么意思?
-
实际上我是从登录页面发送名称,点击提交按钮后,我想在同一个 login.html 本身的单独 div 中显示名称