admin管理员组文章数量:1026971
I have javascript passing an array to PHP with:
var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.getJSON("rebound.php",
{
'mapIDs[]' : mapIDArray
},
function(output){
console.log(output);
}
);
In rebound.php, I try to read the passed array (var_dump, print_r, etc.), such as:
print_r($_GET['mapIDs[]']);
But no luck...
I have javascript passing an array to PHP with:
var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.getJSON("rebound.php",
{
'mapIDs[]' : mapIDArray
},
function(output){
console.log(output);
}
);
In rebound.php, I try to read the passed array (var_dump, print_r, etc.), such as:
print_r($_GET['mapIDs[]']);
But no luck...
Share Improve this question asked Apr 17, 2012 at 20:51 alyxalyx 2,7436 gold badges45 silver badges69 bronze badges 1-
try
print_r($_GET['mapIDs']);
– Roman Pominov Commented Apr 17, 2012 at 20:57
2 Answers
Reset to default 5You don't need add the []
to the name.
var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.getJSON("rebound.php",
{
mapIDs: mapIDArray
},
function(output){
console.log(output);
});
Then in your PHP: $_GET['mapIDs']
will be an array.
It'd be print_r($_GET['mapIDs']);
on the server-side, and
var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.ajax("rebound.php",
dataType: 'json',
data:
{
'mapIDs[]' : mapIDArray[0],
'mapIds[]' : mapIdArray[1],
},
traditional: true,
success: function(output){
console.log(output);
}
);
on the client side. The key issues being that first, PHP sees it an an array with name 'mapIDs', even though it was mapIDs[] as a GET parameter, and second, multiple fields need multiple entries.
I have javascript passing an array to PHP with:
var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.getJSON("rebound.php",
{
'mapIDs[]' : mapIDArray
},
function(output){
console.log(output);
}
);
In rebound.php, I try to read the passed array (var_dump, print_r, etc.), such as:
print_r($_GET['mapIDs[]']);
But no luck...
I have javascript passing an array to PHP with:
var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.getJSON("rebound.php",
{
'mapIDs[]' : mapIDArray
},
function(output){
console.log(output);
}
);
In rebound.php, I try to read the passed array (var_dump, print_r, etc.), such as:
print_r($_GET['mapIDs[]']);
But no luck...
Share Improve this question asked Apr 17, 2012 at 20:51 alyxalyx 2,7436 gold badges45 silver badges69 bronze badges 1-
try
print_r($_GET['mapIDs']);
– Roman Pominov Commented Apr 17, 2012 at 20:57
2 Answers
Reset to default 5You don't need add the []
to the name.
var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.getJSON("rebound.php",
{
mapIDs: mapIDArray
},
function(output){
console.log(output);
});
Then in your PHP: $_GET['mapIDs']
will be an array.
It'd be print_r($_GET['mapIDs']);
on the server-side, and
var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.ajax("rebound.php",
dataType: 'json',
data:
{
'mapIDs[]' : mapIDArray[0],
'mapIds[]' : mapIdArray[1],
},
traditional: true,
success: function(output){
console.log(output);
}
);
on the client side. The key issues being that first, PHP sees it an an array with name 'mapIDs', even though it was mapIDs[] as a GET parameter, and second, multiple fields need multiple entries.
本文标签: javascriptjQuery getJSONPassing arrays to PHPStack Overflow
版权声明:本文标题:javascript - jQuery $.getJSON : Passing arrays to PHP - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745654994a2161543.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论