php - jquery ajax后混合数组对象将空数组发送到php
问题描述
我向 Php 发送了一个数组/对象组合,但 POST 是空的
控制台日志(数据)
data:
ABONNR: 900000064
UMO301NR: 173088
change:
assistant: [phone: Array(0)]
patient: [phone: {…}, social: "single"]
patient-medical: "Hoge bloeddruk"
patient-name: "Burger Maria SENSO2ME"
remove:
assistant: [{…}, phone: Array(0)]
patient: [phone: Array(0)]
patient-medical: "Evenwichtsproblemen"
jQuery
var json = {data:changed}
console.log(json)
$.ajax({
url: Settings.base_url + '/home/update',
data: json,
type: 'post',
success: function (response) {
console.log(response)
}
});
php print_r($_POST)
Array ( )
你有想法吗 ?谢谢!
解决方案
$_POST[]不会抓取JSON
. 您应该改用file_get_contents()。
// Takes raw data from the request
$json = file_get_contents('php://input');
// Converts it into a PHP object
$data = json_decode($json);
那里有类似的答案:如何在 php 中获取 POST 的正文?
推荐阅读
- javascript - Javascript prevent decrement past 0
- python - 您如何处理在 Python 中生成许多变量或对象的任务?
- c++ - 什么是“#include
“? - python-3.x - 在特定小时之间每 10 秒运行一次 bash 脚本
- c# - Handle Linq queries outputs
- python - 在python中使用for循环时如何更新列表
- javascript - 动态创建的字段/ID 中的 foreach 解决方案
- javascript - 如何让nodejs在继续之前等待mongodb连接(以阻塞方式调用异步)
- angular - Keycloak-angular (keycloak.js) 返回“无法读取未定义的属性‘resourceAccess’”
- java - 如何获取要用作方法参数的类的类型?