zoukankan      html  css  js  c++  java
  • serializeArray()方式请求,php获取的方法

    javascript

            var arry = $("#fm").serializeArray();  // alert(arry);
            
            var url = 'Ajax-index.php?module=<{$module_name}>&action=DetailView_RecingToday_Save'; // 
            //alert(url);
            $.ajax({
                url: url,
                data: { module:"<{$module_name}>" ,action:"DetailView_RecingToday_Save" ,para: JSON.stringify(arry) },
                type:"post",
                success: function (result) {
                    //alert("success");
                    var result = eval('('+result+')');   //必须有    
                    if (result.success==1){   
                        mui.alert("成功确认","消息", function() {  
                            butGoBack_Click(); //在点击后才进行back操作
                        });  
                    }else{
                        mui.alert("保存失败!","消息");
                    }
                }
            })

    这里需要注意的有两点

    1.  var arry = $("#fm").serializeArray();  //form里的值 序列化

    2. JSON.stringify(arry);  //转为 JSON 格式

    php端 $_POST['para'] 为

    [{"name":"id","value":"B365A8E2-B003-27A6-718D-4D8662FEB901"},{"name":"name","value":"王雨晴"},{"name":"sex","value":"女"},{"name":"mobile_tel","value":"159338857883"},{"name":"office_tel","value":""},{"name":"home_tel","value":"11111"},{"name":"other_tel","value":""},{"name":"department","value":"客服部"},{"name":"position","value":"职员"},{"name":"address","value":""},{"name":"description","value":""}]  

    php

         //整合参数
        $json_para = (array)json_decode($_POST['para'], true);
        $para = array();
        for($i=0;$i<count($json_para);$i++) {
            $para[$json_para[$i]['name']] = $json_para[$i]['value'];
        }
        //WriteLog($json_para[0]['name']);WriteLog($json_para[0]['value']);
        //WriteLog($para['receive_money_remind_id']);     

    通过上面的转换  $para['sex'] 就可以 取到 它所对应的值  '女'

  • 相关阅读:
    [APIO2012]派遣
    Luogu_2774 方格取数问题
    Luogu4149 [IOI2011]Race
    Luogu_4886 快递员
    Loj_6282. 数列分块入门 6
    LOJ 6281 数列分块入门 5
    三维偏序 cdq
    【逆序对】 模板
    【luogu P1637 三元上升子序列】 题解
    【luogu P3609 [USACO17JAN]Hoof, Paper, Scissor蹄子剪刀布】 题解
  • 原文地址:https://www.cnblogs.com/hailexuexi/p/13410716.html
Copyright © 2011-2022 走看看