When I call the function I always get an undefined value, I don't understand what can ruin it.

> 
> You are logged in as undefined, Error undefined
> 
> 
> 

***Ajax script:***

```
function Submit() {
   console.log('asd')

   $.ajax({
       url: "Server.php",
       type: "POST",
       dataType: "json",
       data: {
          name: "Test2",
          email: "Test@gmail.com"
       },
       success: function(data, textStatus, jqXHR) {
          console.log("You are logged in as: ", data.name);
          $('#user').html("You are logged in as: " + data.name);
       },
       error: function(request, error, data) {
          console.log(arguments);
          alert(" Can't do because: " + error + " DATA: " + data);
       }
   })
}

```

***PHP Script:***

```
<?php
header("Content-type: application/json; charset=utf-8");

$errors = [];
$data = [];

if (empty($_POST['name'])) {
    $errors['name'] = 'Name is required.';
}

if (empty($_POST['email'])) {
    $errors['email'] = 'Email is required.';
}

if (!empty($errors)) {
    $data['success'] = false;
    $data['errors'] = $errors;
} else {
    $data['success'] = true;
    $data['message'] = 'Success!';
    $data['name'] = $_POST['name'];
}
echo json_encode($data);
?>

```

I tried every solution in vain, so I still get an indefinite value. I’m slowly starting to think there’s nothing wrong with the script.