ajax怎么传递数组到后台,后台在action中怎么去接收
ajax如何传递数组到后台,后台在action中如何去接收
js代码
我通过getParameter接到的值为null,其他的可以接到。想不通啊。
------解决思路----------------------
action 不能接受数组
可以把数组改成字符串
action 中再把字符串个分割成数组
------解决思路----------------------
在前台用json拼接,作为ajax异步请求的参数
在后台action中解析你的json字符串,得到你想要的值
------解决思路----------------------
数组能那样传?
js代码
var arrThis = new Array(new Array(),new Array());
function editResource(){
var mdeiaName = $("#mdeiaName").val();
if(mdeiaName==""){
return;
}
$.ajax({
url:'resManage/editSrcById.action',
type: "POST",
data:{mdeiaName:mdeiaName,id:id,'arr':arrThis},// 你的formid
success: function(data) {
alert(arrThis.length+"===");
alert("修改成功");
}
});
}
@Action(value="editSrcById")
public String editSrcById(){
HttpServletRequest request = ServletActionContext.getRequest();
String mdeiaName = request.getParameter("mdeiaName");
String id = request.getParameter("id");
String arr = request.getParameter("arr");
System.out.println(arr+"===");
return null;
}
我通过getParameter接到的值为null,其他的可以接到。想不通啊。
------解决思路----------------------
action 不能接受数组
可以把数组改成字符串
action 中再把字符串个分割成数组
------解决思路----------------------
在前台用json拼接,作为ajax异步请求的参数
在后台action中解析你的json字符串,得到你想要的值
------解决思路----------------------
数组能那样传?
data:$('#aForm').serialize() ,// 你的formid
serializeObject = function(form) {
var o = {};
$.each(form.serializeArray(), function(index) {
if (o[this['name']]) {
o[this['name']] = o[this['name']] + "," + this['value'];
} else {
o[this['name']] = this['value'];
}
});
return o;
};