从表单 express/js/mongo 发出两个不同的 POST 请求


   <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>

我只想在表单中添加更新和删除按钮,并将请求发送到快递客户。但是我该怎么做呢?

在这里,数据从 mongo db 加载。那么如何从同一表单发送不同的帖子请求???

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

为提交按钮指定名称和不同的值。

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

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

在服务器上,检查 req.body.action 的值并采取相应的措施。

最新更新