php - jQuery $.getJSON : Passing arrays to PHP

标签 php javascript jquery get

我有 javascript 将数组传递给 PHP:

         var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];

         $.getJSON("rebound.php",
            { 
                'mapIDs[]' : mapIDArray
            },

            function(output){

                console.log(output);

            }
        );

在rebound.php中,我尝试读取传入的数组(var_dump、print_r等),如:

print_r($_GET['mapIDs[]']);

但运气不佳...

最佳答案

您不需要将 [] 添加到名称中。

var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.getJSON("rebound.php",
{ 
   mapIDs: mapIDArray
},
function(output){
    console.log(output);
});

然后在您的 PHP 中:$_GET['mapIDs'] 将是一个数组。

关于php - jQuery $.getJSON : Passing arrays to PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10198968/

相关文章:

javascript - 如何将函数转换为 MooTools?

javascript - 如何使用 'javascript variable as a text' ?

php - Laravel 7:MariaDB与Redis结合使用,但是Redis在大型对象上的运行速度较慢

php - 如果其他字段存在验证错误消息,输入值将转换为垃圾值

javascript - 在 React 组件的文本框中复制文本的粘贴

javascript - 干 - 嵌套 if 语句

jquery - 将 onclick 事件添加到 td,但不应在其中的链接上触发

javascript - javascript 中只读的选项,然后禁用复选框属性

php - 如何将一个表中的值数组匹配到另一个表并使用 php 显示匹配的值

javascript - 限制来自输入和文本区域的坏词