douti0687 2012-03-24 20:13
浏览 111
已采纳

jQuery重定向传递数组

On my site, users choose colors they want and after making their selections they proceed to the next page. Currently, every time they click on a color, I add it to a JavaScript array. When they are ready to go to the next page, I want to pass this array of colors so I can display their chosen colors on the next page. So my question is how can I accomplish this with jQuery or PHP?

Thanks.

  • 写回答

2条回答 默认 最新

  • doupu5941 2012-03-24 20:16
    关注

    You can pass the array in this way:

    $.post('URL_Of_Next_Page', {'MyArray': actualArray});
    

    To do the redirect, then you can do this:

    window.location.replace("URL_Of_Next_Page");
    

    I am not sure, but if you do the post before the redirect, then it might have the array, but I doubt it. You can either store the array in a session variable or you can do as safarov suggested and pass it via query parameters.

    For the session approach

    $_SESSION['MyArray'] = json_encode(actualArray);
    

    Then to get it back:

    actualArray = json_decode($_SESSION['MyArray']);
    

    To get it JSONified to use as a string:

    var actualArrayAsString = JSON.stringify(actualArray);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件