$data = ['success' => false; 'message' => 'Тест', 'phone' => $_POST['phone']];
header('Content-Type: application/json');
echo json_encode($data);
$.ajax({
type: 'post',
url: '/script.php'. // без http:// и домена
dataType: 'json',
data: {id: 5555, phone: 4444},
success: function(data) {
if (!data.success) {
$("#error").html(data.message);
console.log(data.phone); // 4444
}
}
});
$json = $_POST['data']; //json need to be data
$info = json_encode($json);
$file = fopen('test.json','w+') or die("File not found");
fwrite($file, $info);
fclose($file);
exit;
file_put_contents('test.json', json_encode($_POST['data']));
exit;