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'] 就可以 取到 它所对应的值 '女'