Ajax 实现数组传递(Java)

jsp前端:

var ids = [];
        var rows=$("#tt").datagrid("getSelections");
        for(var i=0; i<rows.length; i++){
            ids.push(rows[i].phonenumber);
            }
       $.ajax({
            async : false,
            cache : false,
            traditional: true,
            type : 'POST',
            data : {
                ids:ids
            },
            url : "personalInfoController.do?SendMSG",// 请求的action路径
            error : function() {// 请求失败处理函数
            },
            success : function(data) {
                var d = $.parseJSON(data);
                if (d.success) {
                    var msg = d.msg;
                    tip(msg);
                }
            }
        });

java后台接收:

    /**
     * @return
     */
    @RequestMapping(params = "SendMSG")
    @ResponseBody
    public AjaxJson SendMSG(HttpServletRequest request, String[] ids) {
        String[] idr = ids;
        String phones="";
        AjaxJson json = new AjaxJson();
        json.setSuccess(false);
        for(int j=0;j<idr.length;j++){
            if(j!=0){phones+=",";}
            phones+=idr[j];
        } 
    json.setSuccess(true);
        return json;
    }

 

千里之行始于足下
posted @ 2017-01-18 17:39  ybyi  阅读(39794)  评论(1编辑  收藏  举报