ajax提交json格式数组

        var userArr = new Array();

        var user = {};
        user.name = "张三";
        user.age = 24;
        userArr.push(user);

        user.name = "李四";
        user.age = 26;
        userArr.push(user);

        $.ajax({
            url: "/mysql/lian/txlian",
            type: "POST",
            async: false,
            contentType : 'application/json;charset=utf-8', //设置请求头信息
//            dataType:"json",
            data: JSON.stringify(userArr),    //将Json对象序列化成Json字符串,JSON.stringify()原生态方法
//            data: $.toJSON(customerArray),            //将Json对象序列化成Json字符串,toJSON()需要引用jquery.json.min.js
            success: function(data){
                window.location.href="/mysql/lian/qrxxl";
            },
            error: function(res){
                alert(res.responseText);
            }
        });        

 

posted @ 2019-08-28 13:55  无知死循环  阅读(4801)  评论(0编辑  收藏  举报