jeudi 21 juillet 2016

AJAX POST request to Spring MVC Controller not working

I am facing the error:

Failed to load resource: the server responded with a status of 415 (Unsupported Media Type)

AJAX portion of my code is as follows:

$.ajax({ 
    url: '/authentication/editUser',    
    type: "POST", 
    contentType: "application/json",
    data: JSON.stringify(requestObj), //Stringified JSON Object

    success: function(resposeJsonObject) {
       //
    }   
});

And the controller's handler method:

@RequestMapping(value = "/editUser", method = RequestMethod.POST, 
    headers = {"Content-type=application/json"})
@ResponseBody
public  EditUserResponse editUserpost(@RequestBody EditUserRequest editUserRequest) {
    System.out.println(editUserRequest);
    return new EditUserResponse();
}

How to resolve the error?

Aucun commentaire:

Enregistrer un commentaire