taboubim taboubim - 1 year ago 110
Ajax Question

POST request returns 415 - Unsupported Media Type

Even if this error is known, I was not able to solve my issue!

The reset Service is declared in this code :

public void addProductToShoppingBag(JSONObject object) throws JSONException

and I'm sending a POST request using this javascript :

header: 'application/json',
type: 'POST',
data: $.toJSON({
member_id: "1",
products_id: ["0","1"]
url: url

and I'm getting the 415 - Unsupported Media Type error !!! any idea ?

Answer Source

You want to set contentType. Your header is not formatted properly


 header: 'application/json',


contentType: "application/json;charset=utf-8",

The proper header needs to include 'Content-Type' in it and jQuery will take care of that for you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download