Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call a Spring controller method with Jquery AJAX

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.

like image 294
coder Avatar asked Dec 11 '25 03:12

coder


1 Answers

First, try to see what happens if you hit the URL manually in the browser

If that is successful, turn on request tracking in firebug and see if firefox actually hits the URL (and what the response says)

like image 150
Sean Patrick Floyd Avatar answered Dec 12 '25 18:12

Sean Patrick Floyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!