我有 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/