为什么单击删除按钮时会发送获取请求?

时间:2018-07-21 04:05:36

标签: javascript jsp

<script type="text/javascript">
    $(function() {
      var ids = $ {
        requestScope.ids
      };
      for (let i = 0; i < ids.length; i++) {
        $("#delete-" + ids[i]).click(function() {
          var path = "employees/" + ids[i];
          $("#form").attr("action", path).submit();
        });
      }
    });
</script>

...
        <c:forEach items="${requestScope.employees}" var="employee">
            <tr>
                <td>${employee.id }</td>
                <td>${employee.name }</td>
                <td>${employee.email }</td>
                <!--进行判断:0为男性,1为女性-->
                <td><c:if test="${employee.gender==0}">男</c:if> <c:if
                        test="${employee.gender!=0}">女</c:if></td>
                <td>${employee.department.deptName }</td>
                <td><button id="delete-${employee.id }">DELETE</button></td>
                <td><button>UPDATE</button></td>
            </tr>
        </c:forEach>
    </table>
</c:if>
<form method="post" id="form">
    <input type="hidden" name="_method" value="DELETE" />
</form>

当我单击删除按钮时,我希望表单为post,但是确实如此,但是在Inspect Element中,我看到也正在发送get请求。为什么发送get请求?

enter image description here

请帮助我。

1 个答案:

答案 0 :(得分:0)

问题已解决。错误不是表单发布,而是重定向。我写道:

return "redirect:employees";

当我应该这样写的时候:

return "redirect:/employees";