I'm trying to get the return of the request in the url, with javascript, but I'm having problems.
I have the follow code:
Controller:
@GetMapping("/linguagens")
@ResponseBody
public Map<String, Linguagem> linguagens(){
Map<String, Linguagem> linguagens = new HashMap<>();
linguagens.put("linguagem", new Linguagem("Java", true));
return linguagens;
}
HTML page:
<button id="verLinguagens">Ver linguagens</button>
<div id="linguagens">
</div>
JavaScript code:
$('#verLinguagens').click(function (e) {
e.preventDefault();
$.get("/linguagens")
.done(function (data) {
$('#linguagens').html("Linguagens: " + data.linguagem)
console.log(data.linguagem)
console.log(data)
});
});
In my page show the result, but show like this:
Linguagens: [object Object]
how can I show the correct result? like this
{
"Linguagem": {
"nome": "Java",
"compilada": true
}
}
Thanks!