AJAX request returning error 415

Asked

Viewed 88 times

1

I am new to WEB development and I have a small problem

I created a Java Webservice with only one test method that sums two values received by request parameters. follow it:

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService(serviceName = "WSProtocolo")
public class WSProtocolo {

    @WebMethod(operationName = "soma")
    public Integer soma(@WebParam(name = "x") Integer x, @WebParam(name = "y") Integer y) {
        System.out.println("Funcionou");
        return x + y;
    }
}

and Ajax here who makes the requisition:

$.ajax({
    type: "POST",
    url: "WSProtocolo?wsdl/soma",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    async: true,
    data: JSON.stringify({parametro1: 25, parametro2: 5}),
    success: function (data) {
        alert(data + ", Sucesso!");
    }
});

in Debug of Chrome it only returns the error

415 (Unsupported Media Type)

someone would know to tell me what is wrong?

  • Why Voce is using stringify in data: ?

No answers

Browser other questions tagged

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