本文介绍了POST阵列通过AJAX Spring的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要发送对象的数组通过jQuery AJAX春天控制器。这里是JavaScript code:
I am trying to send object's array to Spring controller via jQuery AJAX.Here is the javascript code:
var data = new Array();
$.each(products, function (i) {
var temp = {};
temp.orpid = products[i].orpid;
temp.orpah = $('#orpah' + products[i].orpid).is(':checked');
temp.orpad = $('#orpad' + products[i].orpid).val();
data.push(temp);
});
$.postJSON(url + 'save',
data,
function(response) {
if (response.isAuthenticated && response.isAuthorized) {
if (response.hasErrors) {
$('#routeForm').setErrors(response.errors);
hideWait();
}
}
else
redirectToLogin();
});
下面是被发送到服务器的params:一个
Here are the params that are sent to the server:
[{"orpid":10,"orpah":false,"orpad":""},{"orpid":11,"orpah":false,"orpad":""}]
该控制器的方法有如下定义:
The controller's method has following definition:
@RequestMapping(value = "/save", method = RequestMethod.POST, headers = BaseController.AJAX_HEADER)
public ModelAndView save(@RequestBody HandlingOrderProductActionForm form, HttpServletResponse response) {...}
在这里HandlingOrderProductActionForm是:
where HandlingOrderProductActionForm is:
public class HandlingOrderProductActionForm extends BaseForm {
public class ActionForm {
private Boolean orpah;
private String orpad;
private Long orpid;
public ActionForm() { }
public void setOrpah(Boolean orpah) {
this.orpah = orpah;
}
public Boolean getOrpah() {
return orpah;
}
public void setOrpad(String orpad) {
this.orpad = orpad;
}
public String getOrpad() {
return orpad;
}
public void setOrpid(Long orpid) {
this.orpid = orpid;
}
public Long getOrpid() {
return orpid;
}
}
private List<ActionForm> actions;
/**
*
*/
public HandlingOrderProductActionForm() {
super();
}
public void setActions(List<ActionForm> actions) {
this.actions = actions;
}
public List<ActionForm> getActions() {
return actions;
} }
现在的问题是,服务器返回415错误:
The problem is, that the server returns an 415 error:
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().
任何想法?谢谢
Any ideas?Thank you
推荐答案
问题就解决了 - !就在ActionForm中移动到单独的类
THe problem is solved - just move the ActionForm to separate class!
这篇关于POST阵列通过AJAX Spring的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!