0

I send an array / object mix to Php but the POST is empty

console.log (data)

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 ( )

Do you have an idea ? Thx!

2 Answers2

0

$_POST[] will not grab JSON. You should use file_get_contents() instead.

 // Takes raw data from the request
$json = file_get_contents('php://input');
// Converts it into a PHP object
$data = json_decode($json);

similar answer there: How to get body of a POST in php?

Andrii Sukhoi
  • 749
  • 5
  • 14
0
ABONNR: 900000064,
UMO301NR: 173088,
change:
    assistant: {
        phone: []
    },
    patient:{
        phone:
            [current: "22222222222", prev: ""],
        social: "single",
        patient-medical: "Dementie",
        patient-name: "Burger Maria SENSO2ME"
},
remove:
    assistant: {
        0: {name: "WZC Gitschotelhof Loopwacht+"},
        phone: []
    },
    patient: {
        phone: [],
        patient-medical: "Kan niet alleen recht bij val"
    }