0

I'm having some troubles setting up my rest service. I have a js script that collects data from a form, creates a json and sends it throug ajax request to the web service. The problem is that I only got as response: "HTTP Status 415 - Unsupported Media Type"

Here is some code:

Js code for sending request:
    function sendRequest(){
        var json = json_prepare();
        var formData = new FormData();
        formData.append('json', json);
        $.ajax({
         url : 'webapi/tool/insert/data',
         type : 'POST',
         data : formData,
         cache : false,
         contentType : 'application/json',
         processData : false,
         success : function(data, textStatusm, jqXHR){
          console.log("tutto ok");
         },
         error : function(jqXHR, textStatus, errorThrown){
          console.log()("error")
         }
        });
       }

JAVA code of the web service:

 @POST
    @Path("/insert/data")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces("text/plain")
    public Response insertEvent(Request request) throws Exception{
        //deve ricevere un oggetto json con tutti i parametri dell'evento
        log.debug(request.event.descrizione);
        return Response.status(Response.Status.OK).entity("Ricevuto").build();
    }

The Request object is so defined:

  public class Request {
    Event event;
    Gallery gallery;
    List<Activity> activity;

}

0 Answers0