<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
请求?
请帮助我。
答案 0 :(得分:0)
问题已解决。错误不是表单发布,而是重定向。我写道:
return "redirect:employees";
当我应该这样写的时候:
return "redirect:/employees";