我正在尝试向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)
几天前它工作,现在不是.如果需要,我会显示更多代码.谢谢