I'm extremely new to Ajax but have managed the following code but cannot fathom how I process the results to be set into the ajax response then processed.
I have this which sends the correct value of a select dropdown to the Action method:
$('#selectRegionList').on('change', function() {
var request = $.ajax({
url: "/cars/annCreateEdit!updateLocs.jc",
type: "POST",
data: {id: this.value}
});
Which correctly comes to this method in the action and loads a list of Objects (some attribues of the objects are String name, String description, Long id)
public String updateLocs() throws SQLException {
String regionName = findParamStringValue("id");
if (annoEditParams.getRegionStr() == null) {
addActionError("error.region.id.null");
} else {
Region region = new Region();
region.setName(regionName);
criteria.setRegion(region);
annoEditParams.setRegion(jobsService.loadRegion(criteria));
locations = annoEditParams.getRegion().getLocations();
}
return "jsonResult";
}
I have the jsonResult for the action mapped to:
<result name="jsonResult" type="json">
<param name="root">locations</param>
<param name="location">/WEB-INF/jsp/locs.jsp</param>
</result>
And finally the correct result is being called (I know because the existing list (if I load one using the regular submit button) is being cleared)
request.done(function(response) {
$('#selectLocationList option').remove();
//what do i do here ? :o(
});
- but I've no idea what I have to do next to
The part of the page I'd like to populate is a struts2 select tag as follows:
<s:select
key="label.select.location"
list="annoEditParams.region.locations"
name="annoEditParams.locationStr"
listKey="name"
listValue="description"
multiple="false"
size="1"
value="%{annoEditParams.locationStr}"
disabled="%{annoEditParams.region.locations.size == 0}"
id="selectLocationList"
cssClass="span2"
/>
1: access the correct parameter that contains the list that I've loaded
2: if I have to 'set' that list in some special object for access back on the jsp
3: maintain my sanity :-/
Assistance/guidance would be very much appreciated.
Thank you!