ajax:
$.ajax({
type: 'POST',
url:rootPath+"/deviceInfo/saveElements.do",
dataType: 'json',
contentType: "application/json",
data:JSON.stringify(elements),
success:function(){
}
});java:
public Result<Boolean> saveElements(@RequestBody List<ElementInfo> elements){注意点:
data名字不能给名称,给了会报错
错误范例:
$.ajax({
type: 'POST',
url:rootPath+"/deviceInfo/saveElements.do",
dataType: 'json',
contentType: "application/json",
data:{“elements”:JSON.stringify(elements)},
success:function(){
}
});

本文介绍了一种使用AJAX进行POST请求与Java后端交互的方法。重点在于正确设置contentType为application/json,并直接使用JSON.stringify将JavaScript对象序列化为JSON字符串发送,避免使用data对象导致的错误。
194

被折叠的 条评论
为什么被折叠?



