Ajax callback using Spring MVC does not work

Asked

Viewed 136 times

0

Well, I’m trying to make a simple phone call AJAX (which already works), but the callback is not "triggered":

$('#negotiation-status').on('click', '#button-add-destination', function (e){
       var departure =  $('#input-departure').val();
       var arrive = $('#input-arrive').val();
       var ckb = $('#ckb-label').val();
       var price = $('#input-price').val();
       var saleType = $('#ckb-saleType').val();

       $.ajax({
        type:'POST',
        dataType: 'html',
        data: "departure="+departure+"&"+"arrive="+arrive,
        url:'/viatge/auth/addSelectedDestination?${_csrf.parameterName}=${_csrf.token}',
        sucess: function (result){
            alert("Aqui ele funcionou..." + result);
        }, 
        error: function(error){
            alert("Aqui ele deu erro..." + error);
        }
       });
       e.preventDefault();
       return false;
   });

I am using the Spring MVC, below is the method responsible for handling the request and send a reply:

@RequestMapping(value="/addSelectedDestination", method=RequestMethod.POST)
public @ResponseBody String addSelectedDestination(@RequestParam(value="arrive", required=true) String arrive,
        @RequestParam(value="departure", required=true) String departure){

    DestinationRequested destinationRequested = new DestinationRequested();

    destinationRequested.setArrivalDate(arrive);
    destinationRequested.setDepartureDate(departure);

    selectedDestination.add(destinationRequested);

    return arrive + departure;

}

The problem is that the alert(); in the sucess is not fired!

  • You happen to be getting into the method addSelectedDestination correctly?

  • yes @denisazevedo, it enters. The problem is being the same callback.

1 answer

1


It seems that it is a typo, is written sucess with only one c, when the right is Success. Remember to check these details on documentation.

  • It sounds like a joke @Juliano, but that’s what it was. Extreme lack of attention from me. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.