2017-04-20 90 views
0

有沒有辦法在同一個表單標籤中有POST和DELETE請求?我有一張桌子,我想在選擇時刪除那一行。以相同的形式刪除和POST

我似乎只能得到一個,但不能同時工作。我在後端使用Node.js和MySQL。

<form action="" method="post"> 
    <div class="container-fluid"> 
     <div class="row"> 
     <div class="col-lg-6" class = "text-center"> 
      <h2>Responsibility Day!!</h2> 
        <table class="table table-striped" id="tab"> 
        <thead> 
         <tr> 
         <th>Name</th> 
         <th>Task</th> 
         <th></th> 
         </tr> 
        </thead> 
        <tbod> 
         <% for(var i=0; i<persons.length; i++){ %> 
         <tr> 
          <td><%= persons[i].name %></td> 
          <td><%= persons[i].task %></td> 
          <td ><a href="/tasklist/<%= persons[i].name%>/<%= persons[i].task%>"><button class="glyphicon glyphicon-remove" ></button></a></td> 
         </tr> 
         <% } %> 
         <tr> 
         <td><input type="text" name="name"></td> 
         <td><input type="text" name="task"></td> 
         </tr> 
        </tbod> 
        </table> 
       </div> 
       </div> 
       <button class="btn btn-primary" id="addToList" type="submit">Submit</button> 
      </div> 
</form> 

回答

0

您不能在HTML表單中使用DELETE方法。您有兩種選擇:

選項1:使用JavaScript發送請求而不是HTML表單。選項2:如果您只想爲您的表單輸入純HTML,則爲每個按鈕分配一個名稱並在您的腳本中檢測該名稱。