i want to update the content of div "output" without reloading the whold page. When the user inputs something and hits the run button, the server will output the evaluation on the div "output". But the following code puts only div "output" on the browser. The other piece of page is gone. what i have done wrong ?
<body>
<div class="container mx-auto">
<div th:insert="fragments/body :: navigation (true, ${spieler.name}, ${spieler.punkte}, ${spieler.level})"></div>
<div class="d-flex justify-content-center">
<label class="text-center mt-4" id="thetext">Du liebst Abenteuer und möchte endlich reisen.<br>
Du hast ein bisschen Geld und das reicht für ein Ticket zur nächsten Insel.<br>
Unglücklicherweise ist dein Schiff in einem Sturm gesunken. <br>
Du hat glück, an einen Strand zu landen. <br><br>
Jetzt musst du die Herausforderungen mit deinen SQL-Kenntnissen meistern.<br>
Je schneller du die Probleme löst, desto besser ist dein Ranking.<br><br>
Viel Spaß !!!<br>
</label>
</div>
<div class="d-flex justify-content-center">
<input id="startButton" onclick="nachsteFrage()" class="btn-secondary mt-4"
type="button" value="Weiter">
</div>
<form method="post" th:action="@{/level1-answer}" th:object="${answer}">
<div class="form-group">
<input type="text" class="form-control mt-4" id="codeArea" name="antwort" th:field = "*{SQL}"
rows="3" placeholder="Hier steht dein Code ...">
<br>
<div class="d-flex justify-content-center">
<button onclick="updateOutput()" class="btn-secondary mt-4"
id="ausfuehrenBtn">run</button>
</div>
</div>
</form>
<div id="output" style="overflow:scroll; height:400px;">
<span th:text = "${evaluation}"></>
</div>
</div>
<script th:inline="javascript">
function updateOutput() {
$.get("output").done(function(fragment) {
$("#output").replaceWith(fragment);
});
}
</script>
</body>
the controller
@RequestMapping(value="/level1-answer", method=RequestMethod.POST)
public String postSQL (Model map, @ModelAttribute("answer") Answer answer) {
map.addAttribute("evaluation",answer.getSQL() + " this is correct or incorrect");
return "level1 :: #output";
}
the html file is in templates/level1.html