相关疑难解决方法(0)

POST JSON失败,415不支持的媒体类型,Spring 3 mvc

我正在尝试向servlet发送POST请求.请求以这种方式通过jQuery发送:

var productCategory = new Object();
productCategory.idProductCategory = 1;
productCategory.description = "Descrizione2";
newCategory(productCategory);
Run Code Online (Sandbox Code Playgroud)

newCategory在哪里

function newCategory(productCategory)
{
  $.postJSON("ajax/newproductcategory", productCategory, function(
      idProductCategory)
  {
    console.debug("Inserted: " + idProductCategory);
  });
}
Run Code Online (Sandbox Code Playgroud)

和postJSON是

$.postJSON = function(url, data, callback) {
    return jQuery.ajax({
    'type': 'POST',
    'url': url,
    'contentType': 'application/json',
    'data': JSON.stringify(data),
    'dataType': 'json',
    'success': callback
    });
};
Run Code Online (Sandbox Code Playgroud)

使用firebug,我看到JSON正确发送:

{"idProductCategory":1,"description":"Descrizione2"}
Run Code Online (Sandbox Code Playgroud)

但我得到415不支持的媒体类型.Spring mvc控制器有签名

    @RequestMapping(value = "/ajax/newproductcategory", method = RequestMethod.POST)
public @ResponseBody
Integer newProductCategory(HttpServletRequest request,
        @RequestBody ProductCategory productCategory)
Run Code Online (Sandbox Code Playgroud)

几天前它工作,现在不是.如果需要,我会显示更多代码.谢谢

ajax post spring json http-status-code-415

167
推荐指数
8
解决办法
42万
查看次数

标签 统计

ajax ×1

http-status-code-415 ×1

json ×1

post ×1

spring ×1