简体   繁体   中英

how to pass jquery variables using php session variables

 <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?

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM