Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dojo /JSON post request on method with multiple parameters?

This should be basics but I'm having trouble with posting multiple parameters from dojo on a rest endpoint. I have the following method on my back end exposed via resteasy.

@POST()
@Path("/updateProduct")
@Consumes(MediaType.APPLICATION_JSON)
public void updateGeneralSettings(String session,Product product) {
    System.out.println("session"+session);
    System.out.println("product"+product.toString);
}

This works perfectly fine just with Product as the parameter. I'm yet to figure out how to build a jason string with another parameter. Product data just binding from form and this is some additional parameter I wanted to attach with it (i.e. session).

jsonData = dojo.toJson(product)

var handler = request.post(url, {
    data: jsonData,
    headers: {
        "Content-Type": 'application/json; charset=utf-8',
        "Accept": "application/json"
    }
});

Appreciate if you guys can give me some solution.

like image 838
Charith De Silva Avatar asked Feb 14 '26 10:02

Charith De Silva


1 Answers

Try adding parameter names to your method signature:

public void updateGeneralSettings(@FormParam("session") String session, @FormParam("product") Product product)

and then something like:

var handler = request.post(url, {
    data: {
      session: session,
      product: jsonData
    },
    headers: {
      "Content-Type": 'application/json; charset=utf-8',
      "Accept": "application/json"
    }
});
like image 185
condit Avatar answered Feb 17 '26 08:02

condit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!