1.ajax提交添加”traditional:true”参数
注:https://blog.csdn.net/loster_Li/article/details/80916279
https://blog.csdn.net/ojackhao/article/details/24580437
http://www.anyrt.com/blog/list/submit.html
2、前端向后台传送数组参数的3种方法
https://blog.csdn.net/xsyl08/article/details/82699494
<script type="text/javascript">
$(function(){
$("#reserve_btn").click(function(){
if($('#dg').datagrid('getSelections').length==0){
$.messager.alert("消息提示",'请选择要预订的房间','error');
}else{
var room_nos=[];
var array=$('#dg').datagrid('getSelections');
for(var i in array){
room_nos.push(array[i].room_no);
}
console.log(room_nos);
$.post('../clientController/reserveRooms.action',{'room_nos':room_nos.join(',')},function(flag){
alert(flag)
})//方法一:数组转化成字符串,传字符串到后台
/* $.post('../clientController/reserveRooms.action',{'room_nos':JSON.stringify(room_nos)},function(flag){
alert(flag)
})//方法二:数组转化成json字符串,传json字符串到后台
$.ajax({
url: '../clientController/reserveRooms.action',
type: 'post',
data: {'room_nos':room_nos},
traditional:true,//用传统方式序列化数据
success:function(flag){
alert(flag)
}
})//方法三:通过设置traditional属性为true直接传递数组 */
}
})
})
</script>