设置请求头:

headers:{'Content-Type': 'application/json'},

示例:

//1.处理传递数据
var formData = $('#inputForm').serializeObject();//序列化表单数据
var jsonData = JSON.stringify(formData);//转为json字符串

//2.发送请求
$.ajax({
url:"${ctx}/mdmdecodeapplyservice/mdmDecodeApplyService/applyDecode",
type:"post",
data:jsonData,
dataType:'json',
headers:{'Content-Type': 'application/json'},//设置请求头
success:function(data){

},
error:function(e){
console.log('ajax请求异常,异常信息如下:', e);
}
});

/**
* 序列化表单()
*/
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [ o[this.name] ];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};

附:后台代码

@Controller
@RequestMapping(value = "${ctx}/mdmdecodeapplyservice/mdmDecodeApplyService")
public class CodeController {

/**
* 获取编码
* @param jsonStr 参数json字符串
* @return
*/
@RequestMapping(value = "applyDecode", method = RequestMethod.POST, produces = { "application/json" })
@ResponseBody
public String getCode(@RequestBody(required = true) String jsonStr) {
//TODO 业务代码
return "";
}

}