如果我点击一个按钮,那么表单就会提交,并且令人惊讶的是没有错误,但我的问题是如何在没有“表格”的任何属性的情况下提交表单。标记
我应该编写表格标签,如:
<form:Form action="upcomingLeaves.do" commandName="loginform" modelAttribute="loginform"
method="POST">
....
.....
<form:form>
我是这样写的:
<form:form>
<table>
<thead>
<tr style="background-color:#666633;">
<th>Employee id</th>
<th>Leave Balance</th>
<th>Date</th>
<th>Leave Type</th>
<th>Leave Period</th>
<th>Applied Leaves</th>
<th>Status</th>
<th colspan="4">Action</th>
</tr></thead>
<tbody>
<c:choose>
<c:when test="${not empty upcomingLeavesList}">
<c:forEach items="${upcomingLeavesList}" var="upComLeave">
<tr>
<td><span>${upComLeave.employee_id}</span></td>
<td><span>${upComLeave.no_of_leave}</span></td>
<td><span>${upComLeave.fromDate} - ${upComLeave.toDate}</span></td>
<td><span>${upComLeave.leaveType}</span></td>
<td><span>${upComLeave.leavePeriod}</span></td>
<td><span>${upComLeave.appliedLeave}</span></td>
<td id="status"><span>${upComLeave.leaveStatus}</span></td>
<c:if test="${upComLeave.leaveStatus eq 'Pending' }"> <!-- check status if accepted, don't render Accept button -->
<td><button id="btnAccept" name="action" value="Accept${upComLeave.employee_id}">Accept</button></td>
<td><button id="btnReject" name="action" value="Reject${upComLeave.employee_id}">Reject</button></td>
</c:if>
<c:if test="${upComLeave.leaveStatus eq 'Approved' }"> <!-- check status if accepted, don't render Accept button -->
<td><button id="btnCancel" name="action" value="Cancel${upComLeave.employee_id}">Cancel</button></td>
</c:if>
<c:if test="${upComLeave.leaveStatus eq 'Canceled' }"> <!-- check status if accepted, don't render Accept button -->
<td><button id="btnAccept" name="action" value="Accept${upComLeave.employee_id}">Accept</button></td>
</c:if>
<c:if test="${upComLeave.leaveStatus eq 'Rejected' }"><!-- //check status if accepted, don't render Reject button -->
<td><button id="btnReject" name="action" value="Reject${upComLeave.employee_id}">Reject</button></td>
</c:if>
<%-- <c:if test="${upComLeave.leaveStatus eq 'Canceled' }"><!-- //check status if cancel, render cancel button -->
<td><button id="btnAccept" name="action" value="Accept${upComLeave.employee_id}">Cancel</button></td>
</c:if> --%>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
upcomingLeavesList is empty or null..
</c:otherwise>
</c:choose>
</tbody>
</table>
</form:form>
控制器:
@RequestMapping(value = "/upcomingLeaves" ,method = RequestMethod.POST)
public String ApproveLeaves(@RequestParam(required=false , defaultValue="")String aion,@RequestParam(required=false,defaultValue="")String Cancel,HttpServletRequest request, HttpServletResponse response, ModelMap model){...}
单击按钮表单后不应该提交,对吗?执行该任务我使用ajax所以我会为ex编写ajax代码:
$('button').on('click',function(event){
// get the form values
var str = $("#loginform").serialize();
event.preventDefault();
$.ajax({
type: "POST",
url:"upcomingLeaves.do",
data: str,
success: function(response){
// we have the response
alert("Did it....");
window.location.reload(true);
$('#Status').val('');
},
error: function(e){
alert('Error: ' + e);
}
});
});
ajax代码是对的吗? 请帮帮我.......