Ejs表单动作不适用于节点js?

时间:2016-07-21 19:02:14

标签: javascript node.js ejs

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。但是现在,当我按下按钮时,没有任何反应?任何想法?

1 个答案:

答案 0 :(得分:0)

据我所知,formaction 会覆盖当前表单的action,这意味着您需要一个包含按钮的<form>元素:< / p>

<form>
  <button type="submit" formaction="/" formmethod="get" style="width: 8em;">Clear</button>
</form>

(在Chrome中测试)