How do I call a Spring controller method with Jquery AJAX
22,338
try to add this to your jquery
error: function(jqXHR, textStatus, errorThrown) {
alert("error:" + textStatus + " exception:" + errorThrown);
}
}
and you will see if an error occurs
Author by
coder
Updated on October 27, 2020Comments
-
coder over 3 years
I have the following Spring Controller
@Controller @RequestMapping("/accreq")
with the following mapping
@RequestMapping(value = "/defRoles", method=RequestMethod.GET) public @ResponseBody String loadDefaultRoles( @RequestParam(value="idGroup", required=false) String groupID throws ServletException{
I'm trying to call this method with the following jquery ajax
$.ajax({ type: 'GET', url: '/accreq/defRoles', data: {idGroup: $('#infoGroup').val() }, success: function() { alert("success"); } });
Please help me figure out why the Spring method is not being called even though the ajax method is being called when I click a button. I have stepped through the script with firebug and it definitely hits the ajax function.