繁体   English   中英

AJAX请求似乎未收到响应

[英]AJAX request doesn't seem to recieve the response

我有以下代码: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);
}

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

如果我没记错的话

 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.');
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM