0

我有以下代码:AJAX:

 $.ajax({
                url: "mail.php",
                type: "POST",
                data: {first_name:first_name,last_name:last_name,email: email,telephone:telephone,message:message},
                cache: 'false',
                dataType: "json",
                success: function(response) {
                    {
                        if(response.status==1)
                            alert('Email sent!');
                        else
                            alert('Error.')
                    }
                }
            });

PHP:

header('Content-type: application/json');
$to="me@example.com";
$message=$_POST['message']."\r\n"."\r\n".$_POST['first_name'].' '.$_POST['last_name']."\r\n".$_POST['telephone'];
$subject="New Message!";
$email=$_POST['email'];
$headers="From:".$email;
$success=mail($to,$subject,$message,$headers);
if($success)
{
    $done=array("status"=>true);
    echo json_encode($done);
}
else
{
    $done=array("status"=>false);
    echo json_encode($done);
}

在网络面板中,似乎没有收到响应,类型为“待处理”

4

1 回答 1

1

如果我没记错的话,这个

 success: function(response) {
                {
                    if(response.status==1)
                        alert('Email sent!');
                    else
                        alert('Error.')
                }
            }

应该

  success: function(response) {
                    if(response.status==1)
                        alert('Email sent!');
                    else
                        alert('Error.');
            }
于 2013-09-27T07:16:18.723 回答