从PHP获取空的AJAX响应

时间:2016-12-05 17:17:53

标签: javascript php jquery ajax

我有以下代码但是当我签入firebug时它得到一个空的响应。

以下是代码:

function sendemail() {
    var phone = escape($("#phone").val());
    var reason = escape($("#reason").val());
    var fname = "<?= $_SESSION['fname'];?>";
    var lname = "<?= $_SESSION['lname'];?>";
    var email = "<?= $_SESSION['email'];;?>";
    getAjax("ajax.php?action=sendemail3",
        "Please Wait...",
        "phone" + phone +" & reason "+reason+" & fname "+fname+" & lname "+lname+" & email "+email");
}

这是我的PHP代码:

case "sendemail3":
$name = $_REQUEST['fname'];
$lname = $_REQUEST['lname'];
$to = 'xxx@xxx.edu';
$phone = $_REQUEST['phone'];
$reason = $_REQUEST['reason'];
$subject = 'Verification';
$cont="<html><body style=''> 
<div style='width:100%;' >
<div style='width:50%;margin-left:20%'; >
<div style='text-align:center;font-size:16px;padding:5px;'>
<p>Hi $name $lname,</p>
<p>Thank you <p/>
 </div></div></div>
</body></html>";            
mail ($to, $subject, $cont);
echo "successfully sent";
break;

编辑getAjax函数

function getAjax(e, t, n) {
var a = null;
return $.ajax({
    url: e,
    beforeSend: function() {
        $("#notify-container").show(), $("#msg").empty().html(t)
    },
    success: function(e) {
        "gotosearch" == e && (window.location.href = "search.php"), "gotoprofile" == e && (window.location.href = "profile.php"), "hostpage" == e && (window.location.href = "search.php"), "tourpage" == e && (window.location.href = "search.php"), "gotohomenot" == e && ($("#email1").val(""), $("#pass1").val(""), $("#invalid").fadeIn("fast"), document.getElementById("invalid1").style.display = "none", document.getElementById("invalid2").style.display = "none"), "gohome" == e && ($("#email1").val(""), $("#pass1").val(""), $("#invalid2").fadeIn("fast"), document.getElementById("invalid1").style.display = "none", document.getElementById("invalid").style.display = "none"), "gonot" == e && ($("#email1").val(""), $("#pass1").val(""), document.getElementById("invalid").style.display = "none", document.getElementById("invalid2").style.display = "none", $("#invalid1").fadeIn("fast"))
    },
    type: "POST",
    data: n,
    async: !1
}), a
}

当我签入firebug时,值会发送到帖子中但是当我看到响应时它是空的。
我能做些什么来解决它?
谢谢。

0 个答案:

没有答案