The code below triggers the error callback function. Can you help me ? Actually the thing I'm trying do is get the data in the form in php and then send back these data in Ajax for further treatments
HTML
<body>
<div>
<form id="user">
NOM : <input type="text" name="name"/>
</form>
<button id="tst" onclick="SHOW();">CLICK</button>
</div>
Javascript
function AFFICHER(){
$.ajax({
type: 'POST',
url: 'http://localhost:8012/myscript.php',
data: $('#user').serialize(),
dataType: "json",
crossDomain: true,
success: function(result) {
console.log(result);
},
error: function(xhr, textStatus, errorThrown) {
console.log('ajax loading error...');
return false;
}
});
}
My PHP
<?php
$decoded = json_decode($_POST['data'],true);
foreach ($decoded as $value) {
echo json_encode($value["name"]);
}
?>
The error is

"The code below triggers the error callback function."- And the error is... ?json_decode()the$_POSTdata, B.$_POST['data']isn't what you think it is, C. gather your array data inside theforeach()loop andjson_encode()is post loop.error()callback function which can offer you greater detail as to what is happening:xhr, textStatus, errorThrownUse those instead of a generic, non-informative error message such as "ajax loading error"echo json_encode($_POST);and be done with it. And since you're return data is expected to beJSON(which it will be), you cannotconsole.log(result)and expect results. You must access the keys directly, ie.console.log(result.name), etc., as determined by the response data.