Answer the question
In order to leave comments, you need to log in
How to extract an object from a form?
Through ajax I pass the form, which has 2 elements:
...
let form = new FormData();
form.append('id', '1');
let data = {"name":"John", "sex":"male", "age":"33"};
form.append('data', data);
...
var_dump($_POST["id"]);
// string(1) "1"
var_dump($_POST["data"]);
// string(15) "[object Object]"
var_dump($_POST["data"]["sex"]);
// string(1) "["
var_dump($_POST["data"] -> sex);
// NULL NULL
Answer the question
In order to leave comments, you need to log in
You cannot pass an object inside form.append () as the second parameter: you can only pass a string or only a file, but not an object! To send objects to the server, you need to use JSON. And by the way, in your example, there is not enough code responsible for submitting the form.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question