drdu53813
drdu53813
2012-05-18 15:18
浏览 54

多个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
    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[]).

    点赞 评论
  • dqoqnmb163241
    dqoqnmb163241 2012-05-18 15:35

    in your php script,

    try var_dum($_POST) in ur if condition where you checking params, possible error causing due to this,

    see wot you see after that var_dump, if u see any problem then change you condition with $_GET or $_REQUEST

    点赞 评论

相关推荐