2017-10-13 106 views
0
<html> 
    <body> 
     <form method='POST'> 
      <p>This is data from the databse</p> 
      <input type='text' placeholder='Update the current text'> 
      <button id="up">Update this</button> 
      <button id="del">Delete this</button> 
     </form>      
    </body> 
    </html> 

我只是想在表单中添加更新和删除按钮,并向express accourding发送请求。但我该怎么做?从表单发送两个不同的POST请求express/js/mongo

这里从mongo db加载数据。那么如何从同样的形式发送不同的帖子请求?

此外,我不想使用AJAX请求。 我已经阅读了一些其他解决方案,但没有一个对我有帮助或者我了解。 所以,请以清醒的方式帮助我。

+0

[HTML5占位符属性不能代替标签元素](http://www.456bereastreet.com/archive/201204/the_html5_placeholder_attribute_is_not_a_substitute_for_the_label_element/) – Quentin

回答

0

给提交按钮一个名称和不同的值。

<button name="action" value="update" id="up">Update this</button> 
<button name="action" value="delete" id="del">Delete this</button> 

只有点击提交按钮才会成功(即出现在提交的数据中)。

在服务器上,检查值req.body.action并相应地采取行动。

+0

必须,谢谢! – Abishek

+0

app.post('/',(req,res)=> {console.log(req.body.action); }); – Abishek

+0

app.post('/',(req,res)=> {console.log(req.body.action); }); – Abishek