多个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

查看全部
drdu53813
drdu53813
2012/05/18 15:18
  • php
  • ajax
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复