简体   繁体   中英

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>

node 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')
});

When I press the clear button, I want to get to upload2.html. But right now, when i press the button, nothing happens? any idea??

As far as I know, formaction overrides the current form's action , implying that you need to have a <form> element that contains the button:

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

(tested in Chrome)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM