PHP返回空POST数组
PHP returning empty POST array
JavaScript jQuery post:
var animals = {
animalsArray: [],
tripId: <?php echo $_GET['id']; ?>
};
$('.student-check').each(function() {
animals.animalsArray.push($(this).attr('id'));
});
var sendMe = JSON.stringify(animals);
$.post("saveChanges.php", sendMe, function(response) {
console.log(response);
}, "json");
PHP处理器:echo json_encode(print_r($_POST, true));
// Array
// (
// )
为什么数组是空的?我张贴数据,但响应返回一个空数组。
您将数据编码为JSON,这不是PHP原生处理表单提交的格式。
移除var sendMe = JSON.stringify(animals);
,将animals
传给$.post
,而不是sendMe
。jQuery将使用HTML表单和PHP支持的标准格式之一对其进行编码。
关于如何获取原始请求正文,请参见这个问题。
也
:
echo json_encode(print_r($_POST, true));
json_encode
和print_r
都是接受数据结构并将其表示为字符串的函数。使用其中一个,而不是两个。
相关文章:
- 使用application/x-www-form-urlencoded使用node.js在post请求中发送数组
- 使用 $.post 发送数组
- Javascript POST数据进入GET PHP数组
- Ajax post后数组在服务器端返回为空
- 通过$.post发送多维数组
- 如何通过POST类型以html形式发送PHP数组
- AJAX中的POST数组
- 如何使用javascript将所选项目放入php post数组中
- node.js请求POST数组“;第一个参数必须是字符串或缓冲区;
- 使用$.post()将PHP数组发送到jQuery,然后循环使用这些值
- 将 php 数组发布到 javascript/jquery 中使用 .post
- 使用从 jQuery $.post 返回的数组
- 如何将带有普通对象集合的 Js 数组对象传递给 ajax post'html' 数据类型中的控制器
- 如何在jQuery中通过.post发送数组
- 通过 POST 从 AngularJS 发送“关联数组”
- jQuery - 在 post request 中传递数组
- ajax post 调用导致将数组发送到弹簧休息控制器时出现 400(错误请求)
- 用Ajax将数组POST到PHP
- 将json对象数组POST到IHttpHandler
- 如何使用 Java 模拟 $.ajax 数组 POST 请求