为什么我要返回一个对象:空原型。在这些教程中,我接下来将使用正文解析器来处理一个表单,该表单允许您以以下格式返回表单:{Alert:“这是一个警报”}。但是我要返回的是:[对象:空原型] {警报:“这是警报”}。
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
// app.use(bodyParser.urlencoded({ extended: false }));
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.listen(3000, function() {
console.log('listening on 3000')
})
app.use(express.static(__dirname + '/public'));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html')
})
app.post('/', urlencodedParser, function (req, res) {
console.log(request.body);
})
Index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="/style.css" media="screen" />
<meta charset="UTF-8">
<title>Alerts</title>
</head>
<body>
<div class="header">
<h1>Header</h1>
<p>By: a a</p>
</div>
<div class="form">
<form action="/" method="POST">
Enter your alert: <input type="text" name="Alert" id="Alert">
<button type="submit">Submit Alert</button>
</form>
</div>
</body>
</html>