dqf98772
2018-06-20 11:00
浏览 51

如何使用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

    打赏 评论

相关推荐 更多相似问题