drdu53813 2012-05-18 15:18
浏览 63
已采纳

多个jquery .ajax函数调用的问题

I have a function that I'm calling that validates a recaptcha, and then depending on whether that validates successfully, sends out an email. I am validating the recaptcha using a jquery .ajax function, and upon successful validation uses another jquery .ajax function to send the email.

Here is the javascript:

function validateCaptcha(){
var isValid = $('#es_contact_form').valid();
var esform = $('#es_contact_form').serialize();
var html = $.ajax({
type: "POST",
url: "scripts/ajax.recaptcha.php",
data: esform,
async: false
}).responseText;

if(isValid)
{
   if(html == "success")
   {
        //alert("Captcha and form are valid");
    //return true;
    var esform2 = $('#es_contact_form').serialize();
    var response = $.ajax({
    type: "POST",
    url: "scripts/ajax.email.php",
    data: esform2,
    async: false
    }).responseText2;
    if(response=="success")
    {
    alert('mail successfully sent');
                    return true;
                }else{
                    alert('mail not sent, please try again');
                    Recaptcha.reload();
                    return false;
                }
            }
            else
            {
                alert('Form valid, captcha bogus');
                $("#captchaStatus").html("Your captcha is incorrect. Please try again");
                Recaptcha.reload();
                return false;
            }
        }else{
            if(html == "success")
            {
                //alert("Captcha's good, but the form aint!");
                Recaptcha.reload();
                return false;
            }
            else
            {
                //alert('Form invalid, captcha bogus...can you do anything right?');
                $("#captchaStatus").html("Your captcha is incorrect. Please try again");
                Recaptcha.reload();
                return false;
            }
        }
    }

Here is the serverside code for the script where I am getting the 500 server error:

<?php

$yourName = 'ES';
$yourEmail = 'rob@domain.com';
$yourSubject = 'ES: contact form';
$referringPage = 'es.domain.com';



function cleanPosUrl ($str) {
$nStr = $str;
$nStr = str_replace("**am**","&",$nStr);
$nStr = str_replace("**pl**","+",$nStr);
$nStr = str_replace("**eq**","=",$nStr);
return stripslashes($nStr);
}
if ( isset($_POST) ) {
$to = $yourEmail;
$subject = $yourSubject;
$message = cleanPosUrl($_POST['name'])."

";
$message .= cleanPosUrl($_POST['remail'])."

";
$message .= cleanPosUrl($_POST['phone'])."

";
$message .= cleanPosUrl($_POST['comments']);
$headers = "From: ".cleanPosUrl($_POST['name'])." <".cleanPosUrl($_POST['remail']).">
";
$headers .= 'To: '.$yourName.' <'.$yourEmail.'>'."
";
$mailit = mail($to,$subject,$message,$headers);
}

    if ( $mailit )
    { ?>success<? }
    else
    { die ("The mail wasn't sent"); }
}
?>

Both ajax.recaptcha.php and ajax.email.php pull from the post and then return "success" if they are successful.

The ajax.recaptcha.php is working fine. But when it gets to the ajax.email.php script, I keep getting a 500 server error in Firebug.

Does anyone have a clue as to why one would work and not the other? The scripts are both in the same folder on the same server, so I can't see why this isn't working.

Any help is greatly appreciated.

Thanks

  • 写回答

2条回答 默认 最新

  • dq13733519262 2012-05-18 15:45
    关注

    There's an extra } in the code.. you should get rid of } right after

    $mailit = mail($to,$subject,$message,$headers);
    

    I completely agree with jugnu, For better debugging in such case you should try using static values to send email. (instead of POST[]).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配