How to consume a Multipart form-data method with void method

Asked

Viewed 174 times

0

How to consume a method Multipart/form-date of a web service made in java, by ajax or jquery?

Below I leave as this the method:

JAVA:

@POST
    @Path("/aprovarCompra")
    @Consumes("multipart/form-data")
    public void aprovarCompra(@FormParam("nrCompra") Long nrCompra,
            @FormParam("usuario") String usuario) {
//aqui faco as validacoes conecto ao banco e aprovo a compra
}

The front end is in nodejs (which I know almost nothing about, and the company chose to do so)

The code I have on the front end is as follows::

$('#aprovar').click(function(){
 $.ajax({
    type: "POST",
    url:"10.0.2.15:7001/ws/resources/Compra/aprovarCompra",
    contentType: "application/x-www-form-urlencoded", 
    data:'nrCompra=12345&usuario=usuarioMaster', 
    success: function (data) {
        alert(data);
    },
    error:function (){
        alert("error ao aprovar a Compra: "+nrCompra);
    }
});
});

1 answer

0

I don’t quite understand the problem, but I believe you are not able to read the input parameters of Webservice.

First thing, change the contentType from the Ajax call to:

contentType: "multipart/form-data"

What can be analyzed later is to check the service call and "debug" the server-side request.

I hope I’ve been helping.

  • I need to consume the webservice by approving the purchase, on the web page with nrCompra and the user. I am trying to do this via ajax but if there is another way I am open to suggestions.

  • the call Ajax, arrives on the server?

  • It’s not coming, I don’t know why a friend asked to install Cors to try later. also I can change the form of the webservice soh need to be separated the front and back end codes

  • you have come to look at the call by the browser development tool network?

  • ola Heber thanks for the help, after installing the Cors plugins in google Chrome everything is working properly.

Browser other questions tagged

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