PHP、JS间json数据的处理

来源:互联网 发布:手机新三板交易软件 编辑:程序博客网 时间:2024/06/07 01:54

JS->PHP

$('#shoping-cart').on('click', function () {var selProductId = document.getElementById('selProduct').getAttribute('alt');var selPrice = document.getElementById('idPrice').innerHTML;// 生成json数据var traJSON     = {};traJSON.pid     = selProductId;traJSON.pprice  = selPrice;traJSON.pnum    = sessionStorage.inputNum;// get方式发送json数据$.get('shopingcart.php', {GET_PID:traJSON}, function(data){    var jsonString = data;    // 由JSON字符串转换为JSON对象    var jsonObject = eval('(' + jsonString + ')');    localStorage.shopingCart = jsonObject.Count;    localStorage.shopingPrice = jsonObject.Price;});
// 取得get发送来的pid、pprice、pnum$pid = $_GET['GET_PID']['pid'];$pprice = $_GET['GET_PID']['pprice'];$pnum = $_GET['GET_PID']['pnum'];

PHP->JS

$arr = array(       'Count' => $allCount,       'Price' => $allPrice    );// 生成json,并返回$jsonstr = json_encode($arr);  echo $jsonstr;  

扩展阅读:
http://blog.sina.com.cn/s/blog_6c81721d0100o2dn.html
http://www.cnblogs.com/xcxc/archive/2012/09/07/2674606.html

0 0
原创粉丝点击