Saturday, February 5, 2011

How do I call a Spring controller method with Jquery AJAX

Programmer Question

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.



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails