-2
我不是在谈论一个Button标签。我正在谈论提交类型的输入标签。我正在使用fs来加载当前页面。我试图学习快递。如何在Express中按下提交按钮时打开页面?
Server.js:
var express = require('express');
var path = require('path');
var fs = require('fs');
var app = express();
app.use(express.static(path.join(__dirname+'/public/')));
app.use(require('body-parser').urlencoded({ extended: true }));
app.get('/', function(a,b,c){
fs.readFileSync('index.html');
});
app.post('/testaction', function(a,b){
console.log(a.body.log);
fs.readFileSync('public/Logged.html');
});
app.listen(3000);
的index.html:
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<form method="post" action="http://localhost:3000/testaction">
<h1>Log This:</h1>
<input type="text" name="log"/>
<input type="submit", value="Press Me!"/>
</form>
</body>
</html>
你能分享一些代码,这将有助于澄清你想要做什么?这听起来像是当客户提交你的表单时,你试图将特定的静态页面发送回客户端,以响应特定的POST请求。 –