编程那点事编程那点事

专注编程入门及提高
探究程序员职业规划之道!

SpringMVC ajax提交json报415错误

具体报错信息如下

HTTP Status 415 -

type Status report

message

description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

我提交的表单内容转成了json,因为不想再做数据转换的代码,我用的是easyui。把更新过的列都读取出来,代码如下所示

var rows = $('#dg').datagrid('getChanges',2);

ajax提交的代码如下所示

$.ajax({
	type: "post",
	url: '',
    	data: $.toJSON(rows),      
	dataType: "json",
	async: false,
    	success: function (data, status) {
    					
	}
},2);

提交ajax就报HTTP Status 415错误了。解决该问题的方法很简单,就是加上代码:contentType: "application/json",具体代码如下

$.ajax({
	type: "post",
	url: '',
    	data: $.toJSON(rows),      
	dataType: "json",
	contentType: "application/json",
	async: false,
    	success: function (data, status) {
    					
	}
},2);

这样就解决415错误提示了。

未经允许不得转载: 技术文章 » Java编程 » SpringMVC ajax提交json报415错误