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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器