简体   繁体   English

javascript变量到php数组

[英]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. 我在这里做了这段代码并做了一些研究,但仍然不知道如何将javascript变量插入php数组。 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[''] . 我想将这个“ id”变量放入$ 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 Javascript代码可以使用以下网址对PHP页面执行XMLHttpRequest:/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. 因此,在php页面中,您可以在$ _GET ['my_array_name']中获得一个数组,其中包含Javascript传递的变量,并且可以从Javascript代码中发回文本以供使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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