I am trying to get the list of objects from controller to view through ajax request.I am getting 406 error while I am trying this.
Failed to load resource: the server responded with a status of 406 ()
My controller is as follows,
@RequestMapping("/getReservationList")
public @ResponseBody List<Reservation> getReservationList()
{
HttpHeaders headers = new HttpHeaders();
List<Reservation> rlist=service.showResults();
System.out.println("size is "+rlist.size());
headers.add("Content-Type", "application/json");
System.out.println("inside controller");
//model.addAttribute("list", rlist);
return rlist;
}
My Jsp page is as follows,
<!DOCTYPE html>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#buttona").click(function(){alert("hell");
$.ajax({url: "getReservationList", success: function(result){
for (var i in result){
// data[i].something, etcale
alert(result[i]);
}
$("#div1").html(result);
}});
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<input id="buttona" type="button" value="Register" >
</body>
</html>