Ajax发布到php错误

I am firing an ajax post to a server side php file.

The php returns an "ok" when succeed or error 404 when error.

This is the ajax method

  var formData = {
        name: $('#name').val(),
        email: $('#email').val()
    };

    // Stop the form actually posting
    // Send the request
    $.ajax({
        url: "myserver/register.php",
        type: "Post",
        data: formData,
        success: function () {
            alert("success");
        },
        error: function(xhr, status, err) {
            alert("readyState: " + xhr.readyState + "
status: " + xhr.status);
            alert("responseText: " + xhr.responseText);
        }
        });

For some reason the call always return an error. In the php the data received and everything works fine but it keep and going to the error .

Here is my php code:

<?php

//return error if fields are not set
if (!isset($_POST['name']) || !isset($_POST['email']))
{
    header('HTTP/1.0 404 Not Found');
    http_response_code(404);
    exit();
}
$from = "New Register <new_comment@user-app.com>";
$to = "new_register@user-app.com";
$subject = "New user just registered user!";
$name = $_POST['name'];
$email = $_POST['email'];

$message = "Name:" . $name . "
" . "Email:" . $email ."
";

mail($to,$subject,$message,"From: " . $from);

http_response_code(200);
echo "ok";
?>

try type: "post",

$.ajax({
        url: "myserver/register.php",  //or full url http://ex.com/myserver/register.php
        type: "post",
        data: {'name': $('#name').val(),'email': $('#email').val()},
        success: function (data) {
            alert("success");
        },
        error: function(xhr, status, err) {
            alert("readyState: " + xhr.readyState + "
status: " + xhr.status);
            alert("responseText: " + xhr.responseText);
        }
});

on your php get data using post:-

$_POST['name']
$_POST['email']