jQuery $ .getJSON:将数组传递给PHP

aly*_*lyx 0 javascript php jquery get

我有javascript将数组传递给PHP:

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

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

            function(output){

                console.log(output);

            }
        );
Run Code Online (Sandbox Code Playgroud)

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

print_r($_GET['mapIDs[]']);
Run Code Online (Sandbox Code Playgroud)

但没有运气......

Roc*_*mat 5

您不需要添加[]名称.

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

然后在你的PHP:$_GET['mapIDs']将是一个数组.