I'm working on a submenu on my website, that has 5 options, each of them is name of a game. When user selects an option, I want my server to print a name of the game, that user selected. Here i have two problems:
- I don't know why after click on a submenu option, I always get the
first game name.
- I don't know how to send a request from a JS to my Spring Boot application, which is a server.
Can you help me? Here is my code:
<ul class="collapse list-unstyled" id="selectGameSubmenu">
<li data-option="League of Legends">
<a href="#"><img src="../../../static/images/league_of_legends/leagueoflegends_icon.png"
alt="" style="width:16px;height:16px"> League of Legends</a>
</li>
<li data-option="Teamfight Tactics">
<a href="#"><img src="../../../static/images/teamfight_tactics/teamfighttactics_icon.png"
alt="" style="width:16px;height:16px"> Teamfight Tactics</a>
</li>
<li data-option="Legends of Runterra">
<a href="#"><img src="../../../static/images/legends_of_runterra/legendsofruneterra_icon.png"
alt="" style="width:16px;height:16px"> Leagends of Runterra</a>
</li>
<li data-option="Valorant">
<a href="#"><img src="../../../static/images/valorant/valorant_icon.png"
alt="" style="width:16px;height:16px"> Valorant</a>
</li>
<li data-option="Counter Strike">
<a href="#"><img src="../../../static/images/counter_strike/counterstrike_icon.png"
alt="" style="width:16px;height:16px"> Counter Strike</a>
</li>
</ul>
$("#selectGameSubmenu").click(function(e){
e.preventDefault();
var option = $("#selectGameSubmenu li").data("option");
console.log(option);
});
@PostMapping("/change-game")
public String changeGame(@RequestParam String game){
System.out.println("Selected option: " + game);
return "index";
}