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 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配