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 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services