var workerEdit = {
id: id,
name: $('#workers_response input[name="name"][data-id="gear-'+id+'"]').val(),
photo: $('#workers_response input[name="pas-scan"][data-id="gear-'+id+'"]')[0].files[0],
bibliography: $('#workers_response textarea[name="bibliography"][data-id="gear-'+id+'"]').val(),
history: $('#workers_response textarea[name="history"][data-id="gear-'+id+'"]').val(),
salary: $('#workers_response input[name="salary"][data-id="gear-'+id+'"]').val()
}
i create this object, then i use ajax to send data throw method POST:
$.ajax({
type: "POST",
url: "/admin-workers/edit_worker.php",
data: 'edit_worker='+JSON.stringify(input_data),
success: function(data) {
var obj = JSON.parse(data);
if(obj.error === undefined) {
console.log(obj);
if(obj.data === null) {
alert("Успех");
}
}
else {
alert("Ошибка: "+obj.error);
console.log(obj);
}
},
});
and in php i use:
$edit_worker = json_decode($_POST['edit_worker']);
$test = $edit_worker->name;
Why doesn't php get the object?
$_POST['edit_worker']doesn't contain valid JSON, does it contain anything at all? What are its raw contents?datashould be a key-value object, not a string. Look at the request.