How do I display the response of a call to a Spring MVC Controller returning HTML? In my Javascript code I make a (GET) call to my Spring Controller. From what I can make is that the response from the call is HTML. I guess I need to replace 'alert(response)' with Javascript to display the html.
My Javascript code:
$('#parcelsTable').on( 'click', 'tr', function () {
var data = table.row( this ).data();
$.ajax({
url:"/parcel/showFormForUpdate",
type:"GET",
data:{parcelId:data.parcelId},
success: function(response){
alert(response)
}
});
} );
My controller code in Spring:
@GetMapping("/showFormForUpdate")
public String showFormForUpdate(@RequestParam("parcelId") int theId, Model theModel) {
Parcel theParcel = parcelService.findById(theId);
theModel.addAttribute("theParcel", theParcel);
return "parcel-form";
}
Here "parcel-form" is the name of a template.