嗨我选择一个下拉框时有两个下拉框。第二个下拉列表必须显示使用ajax从控制器获取的值列表。当我使用此逻辑时,第二个下拉列表值未显示。这些是下拉列表:
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>
我的ajax电话:
function test(){
$(document).ready(function() {
$("#contact form").load("ajaxTournament", {
tournId : $('#tournId').val()
}, function(data) {
$("#players").html(data);
});
});
}
控制器方法:
@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;
}
}
你能否提出解决这个问题的建议。感谢您提供宝贵的信息。