使用ajax表单不能确认成功

i'm trying to write a contact form for Wordpress with ajax. I have a problem on success, because jquery doesn't append the confirm.

PHP function

add_action('wp_ajax_submit_form', 'submit_form_callback');
add_action('wp_ajax_nopriv_submit_form', 'submit_form_callback');

function submit_form_callback(){

    $params = array();
parse_str($_POST['data'], $params);

$name = sanitize_text_field (trim( $params['name_contact'] ) );
$email = sanitize_email( $params['email_contact'] );
$message = wp_kses_data( $params['message_contact'] );
$subject = __('e-mail from ', 'ddflatro' ).get_bloginfo( 'url' ) ;
$site_owners_email = get_bloginfo('admin_email');

if ($name=="") {
    $error['name'] =  __( 'Please enter your name', 'ddflatro' );   
}

if ( !preg_match( "/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email ) ) {
    $error['email'] =  __( 'Please enter a valid email address', 'ddflatro' );  
}
else
{
    $mailcheck = spamcheck($email);
    if ($mailcheck==FALSE) {
      $error['email'] =  __( 'Please enter a valid email address', 'ddflatro' );
    }   
}

if ($message== "") {
    $error['message'] = __( 'Please leave a message', 'ddflatro' );
}
if (!$error) {

    $success['success'] = __('Yeah', 'ddflatro' );

    echo json_encode($success);

    $headers[] = 'From: ' . $name . ' <' . $email . '>' . "
";
    $headers[] = 'Content-type: text/html' . "
";

    wp_mail( $site_owners_email, $subject, $message, $headers );


} # end if no error
else {
    echo json_encode($error);

}

die(); // this is required to return a proper result

}

jQuery

$( "#contact-ddf" ).submit(function( event ) {
        event.preventDefault();
        $('#response').empty();
        var data = {
            action: 'submit_form',
            data: $( this ).serialize()
        };
        $.post(ajaxurl, data, function(response) {
            console.log(response);
            if(response.success){
                $('#response').append(response.success);
            }
            alert( response );
            if(response.name){
                $('#response').append(response.name + "<br>");
            }
            if(response.email){
                $('#response').append(response.email + "<br>");
            }
            if(response.message){
                $('#response').append(response.message + "<br>");
            }
            if(response.subject){
                $('#response').append(response.subject + "<br>");
            }
        },'json');
});

If missing name or email or the message jQuery append the notice, but when the email is send nothing happen.

I found no typo or something strange. You could try to define the header like this:

$headers = array('Content-Type: text/html; charset=UTF-8');

Notice: There is a problem with the mail header take a look at this: http://core.trac.wordpress.org/ticket/23578

Rgds, Florian

Please add the line here and try:

$.post(ajaxurl, data, function(response) {
response = jQuery.parseJSON(response);      // this line should add to parse json
console.log(response);