Answer the question
In order to leave comments, you need to log in
How to send JSON with nested objects/arrays via Ajax and parse it on the server in PHP?
Hello.
I can't figure out how to transfer my object to the server and parse it there. View object:
var data = {data: {
name: '',
birth_date: '',
family_status: '',
citizenship: '',
country: '',
area: '',
register: {
city: '',
street: '',
building: '',
flat: ''
},
live: {
reg: '',
city: '',
street: '',
building: '',
flat: '',
flat_type: 'в личной квартире'
},
home_phone: '',
mob_phone: '',
skype: '',
email: '',
no_relatives: false,
relatives: [
{
name: '',
status: 'мать',
birth_year: '',
address: '',
position: '',
work: ''
}
]
}}
axios.post('demo.ru/ajax.php', data, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
<?
if (isset($_POST)) {
$decodedArray = json_decode($_POST,true);
}
var_dump($decodedArray);
?>
Answer the question
In order to leave comments, you need to log in
<?php
if (isset($_POST)) {
$json = file_get_contents('php://input');
$decodedArray = json_decode($json, true);
}
var_dump($decodedArray);
?>
<?php
//print_r($_POST);
if (!empty($_POST[json_name])) { $json_data = $_POST['json_name'];$json = json_decode($json_data,true); $a = $json['name'];$b = $json['idtime'];
if ($a !== false) {
var data = data: {
name: '',
------------------
json_name="+data ;
Why decode on the PHP side at all? Try to write print_r($_POST) on the PHP side, judging by the code, your structure should be there
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question