Joan_wj 2016-06-09 16:58 采纳率: 0%
浏览 1446

jQuery+cookies写的购物车怎么获取值再下订单给数据库插入?

 /*
    | ----------------------------------------------------------------------------------
    | Shopping cart - Fetch Cookie data and display cart items购物车-获取Cookie数据并显示购物车条目
    | ----------------------------------------------------------------------------------
    */
    function output_cookie()
    {
        var cookie = $.cookie('cart'); /*获取cookie*/
        if ( cookie === undefined ) return;
        cookie = $.parseJSON(cookie);


        for ( var x in cookie )
        {
            temp = cookie[x].price;
            temp = temp.replace( /^\D+/g, '');/*\d表示数字, + 表示一个或多个,就是把连续的多个数字替换为空*/
            temp = parseFloat(temp).toFixed(2);/*parseFloat(1.2222).toFixed(2);    ///1.22 */

            var $new = $('<tr> \
                            <td> \
                                <a class="entry-thumbnail" href="' + cookie[x].thumbnail + '" data-toggle="lightbox">\
                                    <img src="' + cookie[x].thumbnail + '" alt="' + cookie[x].title + '" /> \
                                </a> \
                                <a class="entry-title" href="' + cookie[x].url + '">' + cookie[x].title + '</a> \
                            </td> \
                            <td><span class="unit-price">' + cookie[x].price + '</span></td> \
                            <td> \
                                <div class="qty-btn-group"> \
                                    <button type="button" class="down"><i class="iconfont-caret-down inline-middle"></i></button> \
                                    <input type="text" value="' + cookie[x].qty + '" /> \
                                    <button type="button" class="up"><i class="iconfont-caret-up inline-middle"></i></button> \
                                </div> \
                            </td> \
                            <td class="hidden-xs"><strong class="text-bold row-total">¥' + temp + '</strong></td> \
                            <td class="hidden-xs"><button type="button" class="close" aria-hidden="true">×</button></td> \
                        </tr>');

            $new.appendTo( $('.tbl-cart tbody') );
            $new.find('[data-toggle="lightbox"]').magnificPopup({
                type: 'image'
            });
        }

        update_cart_total();
    }
    output_cookie();




这是在jQuery文件里面,但是我要怎么获取这里面每个cookies的值,然后插入数据库?大神求解!!在线等
  • 写回答

1条回答 默认 最新

  • Go 旅城通票 2016-06-10 01:57
    关注

    看json字符串结构,然后服务器建立json对应的类模型,反序列化为类就可以读取入库了。自己找你使用的服务器端语言如何反序列化json字符串为对象就行了

    
            var cookie = $.cookie('cart'); /*获取cookie*/
            if ( cookie === undefined ) return;
                    alert(cookie)///////////////////////
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题