Ajax sends json data, tomcat returns 400

    This is the background java receiving code. This problem occurred today. At first, nothing was output, but 400 was returned. I think there must be some error messages that are not displayed, so I changed the log level of springframework in the log4j configuration file to: DEBUG

Sure enough, an error message appeared: No content to map due to end-of-input, which should mean that no content was obtained.

Take a look at my Ajax sending code:

$.ajax({
	url: url,
	method : "post",
	contentType: 'application/json;charset=utf-8', // 这句不加出现415错误:Unsupported Media Type
	data: JSON.stringify(res), // 以json字符串方式传递
	success: function(data) {
		console.log(data);
	},
	error: function(data) {
		console.log(data);
	}
});

The problem is that the method : "post" in the code should be changed to type : "post" (I also found it by accident, I don't know the specific reason), and it will return to normal after correction.

---------------------------------------------------

When I saw the comments, I checked, and it turned out to be a problem with the Jquery version:

    Type and method have the same meaning, but mthod is added by version 1.9, so before version 1.9, use type, and then use method ( https://blog.csdn.net/cominglately/article/details/78201697 ). In the picture above I refer to version 1.8.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324473567&siteId=291194637