jQuery $.getJSON : 将数组传递给 PHP
jQuery $.getJSON : Passing arrays to PHP
我有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']
将是一个数组。
它会
在服务器端print_r($_GET['mapIDs']);
,并且
var mapIDArray = ["4f8d7684791635ec2e000000", "4f8cbc087916359181000000"];
$.ajax("rebound.php",
dataType: 'json',
data:
{
'mapIDs[]' : mapIDArray[0],
'mapIds[]' : mapIdArray[1],
},
traditional: true,
success: function(output){
console.log(output);
}
);
在客户端。关键问题是,首先,PHP 将其视为一个名为"mapID"的数组,即使它是 mapIDs[] 作为 GET 参数,其次,多个字段需要多个条目。
相关文章:
- 调用php数组中的JS函数
- 将PHP变量分配给PHP数组
- php数组转换为javascript
- 如何用javascript打印php数组
- 将PHP数组传递给js变量
- javascript变量到php数组
- 如何将JSON编码的PHP数组发送到同一页面上的数据表
- 如何在PHP数组中加载下一个youtube
- 使用Angular.js访问php数组数据
- 将Javascript数组转换为PHP数组
- 使用mysql为JSON php数组分配多个列值
- 如何通过AJAX发送PHP数组
- 使用ajax将php数组传递给javascript
- 在Javascript代码中显示PHP数组变量
- 将php数组转换为javascript数组
- 将 PHP 数组传递给 HTML 页面
- 如何将php数组转换为javascript数组
- PHP 数组到 JavaScript 数组
- 将 JavaScript 数组转换为 PHP 数组
- 将PHP数组发送到Javascript