我有像下面無法阻止實際提交表單
<form:form action="/campaign/delete" modelAttribute="campaignDeleteForm" enctype="multipart/form-data" class="form-inline">
<input type="hidden" name="brandId" value="${brandId}" />
<input type="hidden" name="campaignId" value="${campaign.campaignId}" />
<button class="btn" data-dismiss="modal"><fmt:message key="daydiary.brand.delete.box.confirm.no" /></button>
<button class="btn btn-info btn-campaign-delete"><fmt:message key="daydiary.brand.delete.box.confirm.yes" /></button>
</form:form>
我的Java腳本看起來如下
$("#btn-campaign-delete").click(function(){
var form = $(this).parents('form:first');
doAjaxPost(form);
form.submit();
});
function doAjaxPost(form){
form.on('submit' , function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: form.attr('action'),
data: form.serialize
}).done(function(data) {
});
});
}
形式我看到的是Ajax請求去了服務器和現在網址更改爲/ campaign/delete。我想留在同一頁面上。這可能嗎?
'
<%@ taglib prefix =「form」uri =「http://www.springframework.org/tags/form」%> –