jquery向后台提交数组的代码分析
jquery:向后台提交数组
varresArray=newArray(1,2,3);$.post(prefix+'/save/res/',{
'roleID':$('#roleID').val(),
'resArray':resArray,
},function(result){
top.closeLayer();
if(result.state=='succ'){
top.refreshRight();
top.okLayer('维护角色','保存数据成功');
}else{
top.errorLayer('维护角色','保存数据失败');
}
},'json');
后端接收,以springboot为例:
@RequestParam(name="resArray[]",required=false)String[]resArray
resArray[]必须这样写!
实例补充:
jQuery.ajax向后台传递数组问题
//创建一个测试数组
varboxIds=newArray();
boxIds.push(12182);
boxIds.push(12183);
boxIds.push(12184);
//向后台交互
$.ajax({
url:"/xxx",
type:"GET",
data:{
"boxIds":boxIds,
"boxType":0,
"time":newDate().getTime()
},
success:function(data){
//dosth...
}
});
后台controller代码(SpringMVC)
@ResponseBody
@RequestMapping(value="/box/changeLock")
publicStringchangeLock(finalLong[]boxIds,finalintboxType){
returnlocker_ChangeLockService.changeLock(boxIds,boxType);
}
以上就是毛票票小编结合多篇后整理的相关内容,希望能够帮助到大家。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。