0
我想將我的表單數據顯示到另一個html頁面。這是我的server.js顯示從node.js服務器到html頁面的數據
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var path=require('path');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, '/')));
app.post('/myaction.html', function(req, res) {
res.send('You sent the name "' + req.body.name + '".');
});
app.listen(8080, function() {
console.log('Server running at http://127.0.0.1:8080/');
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Demo Form</title>
</head>
<body>
<div id="contact">
<h1>Enter the values</h1>
<form action="/myaction.html" method="post">
<fieldset>
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your full name" />
<label for="email">Email:</label>
<input type="email" id="email" placeholder="Enter your email address" />
<label for="message">Message:</label>
<textarea id="message" placeholder="What's on your mind?"></textarea>
<input type="submit" value="Send message" />
</fieldset>
</form>
</div>
</body>
</html>
現在,它工作正常,並且名稱中反映myaction.html頁面。但我想稍微設定'myaction.html'頁面的樣式,並使其看起來更具可視性。有沒有辦法在頁面中添加更多的html標籤和文本,或者在已經存在的頁面中顯示錶單數據?
https://expressjs.com/en/guide/using-template-engines.html – Quentin