-1

In my current spring project, I have this method in my controller to where I send request from client via method POST:

@RequestMapping(value="cadastra", method=RequestMethod.POST)
@ResponseBody
public String[] cadastra(@ModelAttribute("object") E object, BindingResult result, @RequestParam(value="file", required=false) MultipartFile file, @RequestParam(value="icone", required=false) MultipartFile icone) {
    String response[] = {"not", "not", "not"};
    if(serv.cadastra(object)) {
        response[0] = "yes";
    }
    if(serv.upload_picture(object, file, "picture")) {
        response[1] = "yes";
    }
    if(serv.upload_picture(object, icone, "icone")) {
        response[2] = "yes";
    }
    return response;
}

In my view, the request is sent through this jquery code:

    $('form.form').ajaxForm(function(data) {
        $("#"+data[0]).css("display", "block");
        $("#image-"+data[1]).css("display", "block");
        $("#icone-"+data[2]).css("display", "block");
        $('form.form').each(function(){
            this.reset();
        });
    });

but, despite the data from the form are being sent and stored in the server, I got no response, due to an error HTTP 406. Anyone can tell me how I should modify this code to accept the array as response to my request?

Kleber Mota
  • 8,521
  • 31
  • 94
  • 188

1 Answers1

0

406 Not Acceptable: The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

Basically, your back-end service is saying that the response type it is returning is not specified in the Accept type HTTP header in your client request, or perhaps you have no Accept header specified at all.

I can't help you with specific code because I'm not familiar with the languages you're using, but in principle you need to find out the response content type returned by service (e.g. "application/json") and provide this (content type) in your request's Accept header so that it knows to return the response in the format you want.

See this post: "Pass accepts header parameter to jquery ajax", about how to provide an Accept header to your service using jQuery.

Community
  • 1
  • 1
djikay
  • 10,450
  • 8
  • 41
  • 52