zoukankan      html  css  js  c++  java
  • 前台ajax传数组,后台java接收

    前台ajax传数组

     var arr = new Array();

    后台java接收

    List<String> arr

    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 + '"}') } }) }
  • 相关阅读:
    connect oralce
    monolog php
    js继承
    前后端交互-一些关于接口设计的思考
    zoom:1;
    H5的新特性及部分API详解
    软文参考
    seo细节
    seo每天要做的事情
    seo(每天要干的哪些事)
  • 原文地址:https://www.cnblogs.com/bbllw/p/10110711.html
Copyright © 2011-2022 走看看