简体   繁体   中英

javascript variable to php array

I've made this code here and done some research and still have no idea how to insert javascript variable into php array. Is it possible, acctually?

<script>
    $(document).ready(function(){
        var count = 1;
        var id = 1;
        $("#b").click(function(){
            for(i = <?php echo $row; ?>; i > 0; i--){
                $("#main").prepend('<div id="first'+count+'"></div>'); 
                count++;
            }
            count = 1;
            for(i = <?php echo $row; ?>; i > 0; i--){
                $('#first'+count+'').text('<?php echo $row['']; ?>'+count+'');
                count++;
                id++;
            }

        });
    });
    </script>

I wanted to put this "id" variable into $row[''] .

Thanks for help.

将$ row计数值存储在隐藏文本中并获得onclick值

It depend by what exactly you want to do but you can do it in some way.

The Javascript code can do an XMLHttpRequest to the PHP page with an url like: /page.php?my_array_name[]=my_value_1&my_array_name[]=my_value_2

So in the php page you get an array inside $_GET['my_array_name'] with the variables passed by Javascript and you can send text back to use from the Javascript code.

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