dqf98772 2018-06-20 11:00
浏览 52
已采纳

如何使用php会话变量传递jquery变量

 <div class="wrap-input100 validate-input bg1 rs1-wrap-input100">
                <div class="contact100-form-btn" id="add_driver">
                <span>
                Add another Driver
                <i class="fa fa-long-arrow-right m-l-7" aria-hidden="true"></i>
                </span>
                </div>
            </div> 


<script>    
 var count = 0;
 jQuery("#add_driver").click(function(){
 count++;
 }); </script>

how can i pass the value of the variable count to the next page using php sessions or any other method? is there any simple way to do it?

  • 写回答

2条回答 默认 最新

  • dousendun8411 2018-06-20 11:16
    关注

    Using Below code you can send count value to secondpage.php and in second page use $_POST['count_var'] to access variable. You can check your success response in success: function (response)

    <script>    
     var count = 0;
     jQuery("#add_driver").click(function(){
     count++;
     $.ajax({
                            type: 'post',
                            url: 'secondpage.php',
                            data: {
                                count_var: count,
    
                            },
                            success: function (response) {
                                 document.getElementById("divid").innerHTML = response;
                            }
                        });
     }); 
    
     </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dqh1992 2018-06-20 11:10
    关注

    use localStorage

    page one

    var count = 0;
     jQuery("#add_driver").click(function(){
         count++;
         localStorage.setItem("count", count);
     });
    

    page two

     alert(localStorage.getItem("count"));
    

    Should be the same domain

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 PCDN如何使用宽带的电视业务通道拨号叠加带宽?
  • ¥15 遇到这种校园宽带网络应该怎么样解决?
  • ¥30 AXI VIP验证多余打印问题
  • ¥15 利用加权最小二乘法求某品牌手机价格指标,已按照总销量计算出权重,各类型号手机价格已知,如何求得价格指标?
  • ¥15 如何自制一个硬件钱包,有兴趣的朋友一起交流
  • ¥15 (关键词-聊天软件)
  • ¥15 求大家看看这个编程的编法没有思路啊
  • ¥20 WSL打开图形化程序子窗口无法点击
  • ¥15 Jupyter Notebook 数学公式不渲染
  • ¥20 ERR_CACHE_MISS 确认重新提交表单