I want to submit a form using ajax post and avoid to refresh the page. I'm using Spring and Jquery.
Someone how can I submit the form over ajax and use the class in the controller to do stuff?
The model Class is Auction (the one I'm trying to submit):
public class Auction {
private int id;
private int userId;
private String dateStart;
private String dateEnd;
private double maxPrice;
private boolean payed;
private boolean delivered;
private boolean scheduledTaskParsed;
private SimpleRegisteredUser user;
private WantedProduct wantedProduct;
(...)
}
and the WantedProduct class is
public class WantedProduct {
private int id;
private String title;
private String description;
private int userId;
private int productStateId;
private String stateDescription;
private int productTypeId;
private String brand;
private String brandURL;
(...)
}
The form to submit is:
<form:form id="new-auction" modelAttribute="auction" action="/product/create/" method="post" enctype="multipart/form-data">
<form:hidden path="id"/>
<form:input path="wantedProduct.title" id="title" maxlength="300" placeholder="${nameLabel}*"/>
<form:input id="uploadFile" path="wantedProduct.photosWantedProduct[0].photo.photoFile" type="file" accept="image/*"/>
<form:select id="productTypeSelect" path="wantedProduct.productTypeId" >
<c:forEach var="t" items="${types}">
<form:option value="${t.id}">
<spring:message code="${t.description}"/>
</form:option>
</c:forEach>
</form:select>
<form:input path="wantedProduct.brand" id="brand" placeholder=""/>
<form:input path="maxPrice"/>
<form:input path="wantedProduct.description"/>
<form:select path="wantedProduct.productStateId" >
<c:forEach var="state" items="${productStates}">
<form:option value="${state.id}">
<spring:message code="${state.description}"/>
</form:option>
</c:forEach>
</form:select>
(...)
</form:form>
Thank you