很少有字段值没有出现在最终输出中,我使用的是 nodejs
Few field values are not showing up in the final output, i'm using nodejs
index.html
<form action="http://127.0.0.1:5555/sign" method="POST">
<div class="main">
<div class="name-container">
<input type="text" class="input" placeholder="First Name" id="fname" />
<input type="text" class="input" placeholder="Last Name" id="lname" />
</div>
<div class="gender_date">
<div class="gen">
<input type="radio" name="gender" value="male" id="male" />
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female" />
<label for="female">Female</label>
<input type="radio" name="gender" value="other" id="other" />
<label for="other">Other</label>
</div>
<div class="date-con">
<input type="date" class="input" id='date' name="bday" />
</div>
</div>
</div>
</form>
post 请求正常工作,但名称未显示。
后端nodejs文件=> serve.js
const express = require("express");
const fs = require("fs");
const bodyParser = require("body-parser");
const app = express();
var urlencodedParser = bodyParser.urlencoded({ extended: false });
app.get("/sign", (req, res) => {
res.send("Hello");
});
app.post("/sign", urlencodedParser, (req, res) => {
res.send(req.body);
let student = req.body;
let students = [];
students.push(student);
let data = JSON.stringify(students, null, 2);
fs.writeFile("./file.json", data, err => console.log("success"));
console.log(students);
});
const PORT = 5555;
app.listen(PORT, err => {
console.log(`Server Running at port: ${PORT}`);
});
file.json: 输出
[
{
"gender": "male",
"bday": "1999-07-05"
}
]
来自 "First Name" 和 "Last Name" 字段的值未显示在最终输出中。
无论我改变什么,我都无法让它正常工作。
提前谢谢你。
试一试
<form action="http://127.0.0.1:5555/sign" method="POST">
<div class="main">
<div class="name-container">
<input type="text" class="input" placeholder="First Name" name="fname" />
<input type="text" class="input" placeholder="Last Name" name="lname" />
</div>
<div class="gender_date">
<div class="gen">
<input type="radio" name="gender" value="male" id="male" />
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female" />
<label for="female">Female</label>
<input type="radio" name="gender" value="other" id="other" />
<label for="other">Other</label>
</div>
<div class="date-con">
<input type="date" class="input" id='date' name="bday" />
</div>
</div>
</div>
</form>
index.html
<form action="http://127.0.0.1:5555/sign" method="POST">
<div class="main">
<div class="name-container">
<input type="text" class="input" placeholder="First Name" id="fname" />
<input type="text" class="input" placeholder="Last Name" id="lname" />
</div>
<div class="gender_date">
<div class="gen">
<input type="radio" name="gender" value="male" id="male" />
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female" />
<label for="female">Female</label>
<input type="radio" name="gender" value="other" id="other" />
<label for="other">Other</label>
</div>
<div class="date-con">
<input type="date" class="input" id='date' name="bday" />
</div>
</div>
</div>
</form>
post 请求正常工作,但名称未显示。 后端nodejs文件=> serve.js
const express = require("express");
const fs = require("fs");
const bodyParser = require("body-parser");
const app = express();
var urlencodedParser = bodyParser.urlencoded({ extended: false });
app.get("/sign", (req, res) => {
res.send("Hello");
});
app.post("/sign", urlencodedParser, (req, res) => {
res.send(req.body);
let student = req.body;
let students = [];
students.push(student);
let data = JSON.stringify(students, null, 2);
fs.writeFile("./file.json", data, err => console.log("success"));
console.log(students);
});
const PORT = 5555;
app.listen(PORT, err => {
console.log(`Server Running at port: ${PORT}`);
});
file.json: 输出
[
{
"gender": "male",
"bday": "1999-07-05"
}
]
来自 "First Name" 和 "Last Name" 字段的值未显示在最终输出中。 无论我改变什么,我都无法让它正常工作。 提前谢谢你。
试一试
<form action="http://127.0.0.1:5555/sign" method="POST">
<div class="main">
<div class="name-container">
<input type="text" class="input" placeholder="First Name" name="fname" />
<input type="text" class="input" placeholder="Last Name" name="lname" />
</div>
<div class="gender_date">
<div class="gen">
<input type="radio" name="gender" value="male" id="male" />
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female" />
<label for="female">Female</label>
<input type="radio" name="gender" value="other" id="other" />
<label for="other">Other</label>
</div>
<div class="date-con">
<input type="date" class="input" id='date' name="bday" />
</div>
</div>
</div>
</form>