Ejs 表单操作不适用于节点 js?
Ejs form action is not working with node js?
Ejs
<h4 style="display: inline">You are Connected to:</h4>
<u style="display: inline"><%= host %>:<%= port%> </u>
</br> </br>
<h4 style="display: inline">Output is:</h4>
<u style="display: inline"><%= temp %> </u> </br>
</section> </br>
<label> Click on graph for live updated graph! </label>
</br></br>
<button type="submit" formaction="/" formmethod="get" style="width: 8em;">Clear</button>
</br> </br>
节点 js
app.post('/output3', function(req, res){
client.once('message', function (message) {
var temp = message.toString(); //here you assign temp variable with needed value
res.render( 'index', {temp:temp, host: HOST, port: PORT})
});
});
app.get('/', function(req, res){
res.sendFile(__dirname + '/upload2.html')
});
当我按下清除按钮时,我想到达 upload2.html。但是现在,当我按下按钮时,没有任何反应吗?有什么想法吗??
据我所知,formaction
覆盖 当前表单的 action
,这意味着您需要一个 <form>
元素包含按钮:
<form>
<button type="submit" formaction="/" formmethod="get" style="width: 8em;">Clear</button>
</form>
(在 Chrome 中测试)
Ejs
<h4 style="display: inline">You are Connected to:</h4>
<u style="display: inline"><%= host %>:<%= port%> </u>
</br> </br>
<h4 style="display: inline">Output is:</h4>
<u style="display: inline"><%= temp %> </u> </br>
</section> </br>
<label> Click on graph for live updated graph! </label>
</br></br>
<button type="submit" formaction="/" formmethod="get" style="width: 8em;">Clear</button>
</br> </br>
节点 js
app.post('/output3', function(req, res){
client.once('message', function (message) {
var temp = message.toString(); //here you assign temp variable with needed value
res.render( 'index', {temp:temp, host: HOST, port: PORT})
});
});
app.get('/', function(req, res){
res.sendFile(__dirname + '/upload2.html')
});
当我按下清除按钮时,我想到达 upload2.html。但是现在,当我按下按钮时,没有任何反应吗?有什么想法吗??
据我所知,formaction
覆盖 当前表单的 action
,这意味着您需要一个 <form>
元素包含按钮:
<form>
<button type="submit" formaction="/" formmethod="get" style="width: 8em;">Clear</button>
</form>
(在 Chrome 中测试)