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数据
	var_dump($uid);//ok
	var_dump($service_num); //ok
	var_dump($pay_name);
	var_dump($sell); //ok
	
    	//die($json->encode($result));
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值