前台ajax传数组,后台java接收


 

 

后端

//添加
    @RequestMapping(value = "checkChoise")
    @ResponseBody
    ResultJson checkChoise(@RequestBody List<String> arr) {
        ResultJson resultJson = new ResultJson();
        System.out.println("str:"+arr);
        resultJson.setStatus(0);
        resultJson.setMessage("添加成功!");
        resultJson.setData(null);
        return resultJson;
    }

 

 

js

//某个角色函数
function comfirm(){

     //获取checkbox[name='check']的值
     var arr = new Array();
     $("input:checkbox[name='check']:checked").each(function(i){
           arr[i] = $(this).val();
     });   
    $.ajax({
        type: "post",//注意不能用get
        dataType: 'json',
        url: "/checkChoise",
        contentType: 'application/json',//这个必须是这个格式
        data: JSON.stringify(arr),//前台要封装成json格式
        success: function (result) {
            if (result.status == 0) {
                
            }
            if (result.message != null) {
                layer.msg(result.message)
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('{"status":"' + XMLHttpRequest.status + '","readyState":"' + XMLHttpRequest.readyState + '","textStatus":"' + textStatus + '","errorThrown":"' + errorThrown + '"}')
        }
    })
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM