dougehe2022 2015-04-22 15:40
浏览 92
已采纳

在Cookie中存储来自Javascript的二维数组

First of all, thanks to everyone that's reading that and trying to help me!

I got an online shop and i have a bi-dimensional array with the products like that:

 1. $arrayProducts[id][0] -> id
 2. $arrayProducts[id][1] -> product name
 3. $arrayProducts[id][2] -> price

etc..

I know isn't the best way to do the system, but it's done like that.

Now, I want to store that bi-dimensional array in a cookie, because what I want to do is to store the cart from the user if they go away from my page, and load that again when they come back.

I think the best way to do it is with cookie, but I don't know if I should do a json_encode and json_decode with that bi-dimensional array, or what is the best way to fix my problem.

  • 写回答

2条回答 默认 最新

  • dongzhuner6981 2015-04-22 15:44
    关注

    Before saving your data to cookie stringify your array.

    var x = JSON.stringify(yourarrayvar);
    

    then save x in cookie.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 请求分析基于spring boot+vue的前后端分离的项目
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?