Hi I Have a two drop down boxes when i select one drop down box.second drop down has to display the list of values getting from controller using ajax.when i using this logic the second drop down list values are not getting displayed. These are the drop down lists:
Jsp page:
<form:select path="tournId" id="tournId" onchange="test()">
<form:option value="">Select Tournament</form:option>
<form:options items="${tournaments}" itemLabel="tournamentName" itemValue="tournamentId" />
</form:select>
<form:select path="playerId" id="players">
<form:option value="">Select Players</form:option>
<form:options items="${players}"itemLabel="playerDetails.playerName" itemValue="playerDetails.playerId"/>
</form:select>
My ajax call :
function test(){
$(document).ready(function() {
$("#contact form").load("ajaxTournament", {
tournId : $('#tournId').val()
}, function(data) {
$("#players").html(data);
});
});
}
Controller method :
@RequestMapping(value = "/ajaxTournament", method = RequestMethod.POST)
public @ResponseBody
List<TournamentPlayers> ajaxTournament(HttpServletRequest request, HttpSession session, @RequestParam("tournId") Long tournId, Model model) {
if (session.getAttribute("user") != null) {
List<TournamentPlayers> tPlayerDetails = tournamentPlayerDao.findTournamentPlayersByTournamentId(tournId);
model.addAttribute("players", tPlayerDetails);
return tPlayerDetails;
}
}
could you please give suggestion to resolve this problem. thanks for your valuable information.