美文网首页
ajax 传复杂参数

ajax 传复杂参数

作者: Sxy97 | 来源:发表于2018-01-30 10:04 被阅读0次
    //传数组
     $.ajax({
                        type: "POST",
                        url: this.url ,
                        data: {
                            uid: [1,2,3,4]
                        },
                        traditional: true,//这里设置为true
                        success: function (data) {
                        },
                        error: function () {
                        }
                    });
    
    //传复杂对象
    例子:{
            com_cat: "炊事班",
            onepeople: "onepeople",
            twopeople: 'twopeople',
            datas: [
                {
                    sname: "电视机",
                    size: "海信T60",
                    unit: "台",
                    price: 6000,
                    expectednum: 2,
                    actualnum: 2,
                    prices: 6000
                },
                {
                    sname: "中性笔",
                    size: "齐心",
                    unit: "支",
                    price: 1.5,
                    expectednum: 50,
                    actualnum: 50,
                    prices: 75
                }
            ]
        }
    
    
    //前台
    $.ajax({
                        type: "POST",
                        url: 
                        data: {
                            com_cat: com_cat,
                            onepeople: onepeople,
                            twopeople: twopeople,
                            datas: JSON.stringify(datas)
                        },
                        traditional: true,//这里设置为true
                        success: function (data) {
                        },
                        error: function () {
                        }
                    });
    //后台解析
        const com_cat = query.com_cat || ''
        const onepeople = query.onepeople || ''
        const twopeople = query.twopeople || ''
        const datas = JSON.parse(query.datas) || ''
    
    

    相关文章

      网友评论

          本文标题:ajax 传复杂参数

          本文链接:https://www.haomeiwen.com/subject/gbuqzxtx.html