Spring MVC and ajax requests
hello guys I'm using Spring 3.1 MVC and I have a simple search form:
HTML Code:
<form:form id="formSearch" method="post" modelAttribute="searchCriteria" >
<div id="freeflowlabel">
<p style="text-align:left;">
<span style="font-family:Arial;font-size:16px;font-weight:bold;font-style:normal;text-decoration:none;color:#333333;">${configProperties['cat.search.title']}</span>
</p>
</div>
<form:input id="freeFlowInputId" path="freeFlowText" />
<p></p>
<div id="advancedSearch">
</div>
<!--input id="searchButtonId" type="submit" value=${configProperties['cat.search.button']} style="cursor: pointer;"-->
<button id="loadDataButton" onClick="loadData()">Search</button>
</form:form>
If I use the button submit (now commented) all is working well and in the server side I have the Model Attribute SearchCriteria containing the input inserted by the user in the form.
Since I would like to search and show a table I would like to update just the table doing an ajax request and this ajax request is executed inside the methos loadData() attached to the search button. In this case I tried three ways:
1) form.submit() nothing happen, on server side the bean has null attributes
2) I'm using YUI as form so I tried to serialize a form but I receive an error: application/x-www-form-urlencoded is not supported
3) I can do a serialization on JSON and send the form value in the body of the ajax POST request; this works but it's not so elegant and then I'm going to lose all the facility provided by form:tags....
How can I solve this problem?
I think that should be a relevant problem the interaction between Ajax and spring so I hope that there is a clean solution
thank you
Daniele Ippoliti