广州传奇网络

地址:广州市天河区东圃大马路富华楼C座

电话:13808825895

邮箱:gz020wbs@163.com

QQ:1564443073

网址:http://www.020wbs.com/

首页 > 二次开发Ecshop二次开发 > ecshop AJAX-POST 多维JSON 数据给PHP处理的方法

二次开发Ecshop二次开发

二次开发Ecshop二次开发

ecshop AJAX-POST 多维JSON 数据给PHP处理的方法

 1. ECSHOP 前端组建 多维JSON
2. 字符串化JSON POST至PHP页面处理
3. PHP转化JSON数据

js 部分

function commit(){

var uid =0;

  if ( document.getElementById("user_useridname").checked){

uid = document.getElementById("username").value;

}else{

 uid = 0;

}

 

  var table1=document.getElementById('goods_info');

  var rows=table1.rows;

  var g_info=[]; //声明数组

 

   for(var i=0;i<rows.length;i++){

var uu = rows[i].cells.length;

if (i>=1){

var j=i-1;

var goods_name = rows[i].cells[0].innerHTML;

var goods_code = utf8_encode(rows[i].cells[1].innerHTML);

var goods_price = utf8_encode(rows[i].cells[2].innerHTML);

var goods_account = document.getElementById(j+'3').value;

var goods_num = document.getElementById(j+'4').value;

var goods_note = document.getElementById(j+'5').options[document.getElementById(j+'5').selectedIndex].value;

var goods_subtotal = rows[i].cells[6].innerHTML;

//填充数据多维json数据

g_info.push({

code: goods_code,

             num: goods_num,

account:goods_account,

note:goods_note,

subtotal:goods_subtotal

});

}

    }

 

var pay_name = document.getElementById('pay_name').options[document.getElementById('pay_name').selectedIndex].value;

var sell = document.getElementById('sell').options[document.getElementById('sell').selectedIndex].value;

var service_num = document.getElementById('service_num').value;

// 将 g_info  字符串化

Ajax.call('order.php?act=ajax_commit_order', 'uid='+uid+'&goods_info='+g_info.toJSONString()+'&pay_name='+pay_name+'&sell='+sell+'&service_num='+service_num, commitOrderResponse, 'POST', 'JSON');

}

 

PHP部分:

elseif ($_REQUEST['act'] == 'ajax_commit_order')
{
include_once(ROOT_PATH . 'includes/cls_json.php');
$json = new JSON();

$uid = $_POST['uid'];

$goods_info = utf8_encode($_POST['goods_info']);// 接收数据 做UTF8转换
//反转义数据格式化
$goods_info = stripslashes($goods_info);
$goods_info = json_decode($goods_info,true);// json 解析

$service_num = $_POST['service_num'];
$pay_name = $_POST['pay_name'];
$sell = $_POST['sell'];

var_dump($goods_info);//正常打印出 多维JSON数据
<span style="white-space:pre;"> </span>var_dump($uid);//ok
var_dump($service_num); //ok
var_dump($pay_name);
var_dump($sell); //ok

<span style="white-space:pre;"> </span>//die($json->encode($result));
}