基于第一个jquery/AJAX/php请求的结果调用另一个jquery/AJAX/php请求失败

基于第一个jquery/AJAX/php请求的结果调用另一个jquery/AJAX/php请求失败,php,jquery,ajax,Php,Jquery,Ajax,我有一个带有验证码的联系我们表单。我提交按钮单击我需要使用第一个AJAX请求执行服务器端验证码验证如果成功,然后我调用第二个AJAX/Jquery/php发送联系我们邮件 但是第一个AJAX调用是成功的,但是第二个没有调用。。请在这方面帮助我 <form id="RegisterUserForm" name="RegisterUserForm" action="" onsubmit="return submitform();" method="post"> <field

我有一个带有验证码的联系我们表单。我提交按钮单击我需要使用第一个AJAX请求执行服务器端验证码验证如果成功,然后我调用第二个AJAX/Jquery/php发送联系我们邮件

但是第一个AJAX调用是成功的,但是第二个没有调用。。请在这方面帮助我

<form
id="RegisterUserForm"
name="RegisterUserForm"
action=""
onsubmit="return submitform();"
method="post">
    <fieldset
    style="border: 0;">
        <table
        width="100%">
            <tr>
                <td
                width="150">
                    <div
                    class="celebrationContent">
                        Name:</div>
                        </td>
                        <td
                        class="style1">
                            <input
                            id="Name"
                            type="text"
                            name="Name"
                            style="border-style: none; background-color: #fffcc4;
                        width: 275px;"
                            />
                            </td>
            </tr>
            <tr>
                <td>
                    <div
                    class="celebrationContent">
                        E-mail
                        id:</div>
                </td>
                <td
                class="style1">
                    <input
                    id="email"
                    type="text"
                    name="email"
                    style="border-style: none; background-color: #fffcc4;
                        width: 274px;"
                    />
                    </td>
            </tr>
            <tr>
                <td
                class="celebrationContent">
                    Phone
                    Number:
                    </td>
                    <td
                    class="style1">
                        <input
                        id="phonenumber"
                        type="text"
                        name="phonenumber"
                        style="border-style: none;
                        background-color: #fffcc4; width: 274px;"
                        />
                        </td>
            </tr>
            <tr>
                <td
                class="celebrationContent">
                    Your
                    Celebration:
                    </td>
                    <td
                    class="style1">
                        <input
                        id="yourCelebration"
                        type="text"
                        name="yourCelebration"
                        style="border-style: none;
                        background-color: #fffcc4; width: 274px; height: auto;"
                        />
                        </td>
            </tr>
            <tr>
                <td
                class="celebrationContent">
                    When
                    is
                    it:
                    </td>
                    <td
                    class="style1">
                        <input
                        type="text"
                        name="datepicker"
                        id="datepicker"
                        style="border-style: none; background-color: #fffcc4;
                        width: 272px;"
                        />
                        </td>
            </tr>
            <tr>
                <td
                class="celebrationContent">
                    Enquiry:
                    </td>
                    <td
                    class="style1">
                        <input
                        type="text"
                        id="Enquiry"
                        name="Enquiry"
                        style="border-style: none; background-color: #fffcc4;
                        width: 272px; height: 70px;"
                        />
                        </td>
            </tr>
            <tr>
                <td
                colspan="2"
                align="left"
                class="celebrationContent">
                    Verification
                    Code
                    </td>
            </tr>
            <tr>
                <td
                align="left"
                colspan="2">
                    <table
                    width="100%">
                        <tr>
                            <td
                            width="32%">
                                <img
                                src="captcha.php"
                                alt="celebration captcha"
                                />
                                </td>
                                <td>
                                    <input
                                    type="text"
                                    id="verificationcode"
                                    name="verificationcode"
                                    style="border-style: none;
                                    background-color: #fffcc4"
                                    />
                                </td>
                        </tr>
                        </table>
                        </td>
            </tr>
            <tr>
                <td
                colspan="2"
                align="center">
                    <input
                    type="submit"
                    id="form_submit"
                    />
                    </td>
            </tr>
            </table>
            </fieldset>
            </form>

姓名:
电子邮件
身份证件:
电话
编号:
你的
庆祝活动:
什么时候
是
它:
查询:
验证
代码
jquery代码是

<script type="text/javascript">
        $(function () {
            $('#datepicker').datepicker('option', 'dateFormat', 'dd-mm-yy');            
        });

        $("#datepicker").datepicker({
            minDate: 0
        });

    function submitform() {

        if (validateCaptach()) {
            var sData = $("#RegisterUserForm").serialize();
             alert('i am here to process..');  
            $.ajax({
                type: "POST",
                url: "thankyou.php",
                data: sData,
                //async: false,
                success: function (data) {
                    if (data == "YESSUCCESS") {
                        alert("Your Query has been sent..");
                       return true;
                    } else {
                        alert("some error please type again...");
                        return false; 
                    }
                }
            });
        }
        return false;
    }

    function validateCaptach() {
        if (validateForm()) {
            var captchaval = $("#verificationcode").val();
            $.ajax({
                type: "POST",
                url: "captchacheck.php",
                async: false,
                data: {
                    verificationcode: captchaval
                },
                success: function (data) {
                    if (data == "SUCCESS") {
                        alert("captchacheck success..");
                        return true;
                    } else {
                        alert("The security code you typed was wrong. Please try again.");
                        return false;
                    }
                }
            });
        }
    }

    function validateForm() {

        if (document.RegisterUserForm.Name.value == "") {
            alert("Please provide your name!");
            document.RegisterUserForm.Name.focus();
            return false;
        }

        if (document.RegisterUserForm.email.value == "") {
            var emailID = document.RegisterUserForm.email.value;
            atpos = emailID.indexOf("@");
            dotpos = emailID.lastIndexOf(".");
            if (atpos < 1 || (dotpos - atpos < 2)) {
                alert("Please enter correct email ID")
                document.RegisterUserForm.email.focus();
                return false;
            }
        }

        if ((document.RegisterUserForm.phonenumber.value == "") || isNaN(document.RegisterUserForm.phonenumber.value)) {
            alert("Please enter your phone Number");
            document.RegisterUserForm.phonenumber.focus();
            return false;
        }
        if (document.RegisterUserForm.yourCelebration.value == "") {
            alert("Please enter your Celebration!");
            document.RegisterUserForm.yourCelebration.focus();
            return false;
        }
        if (document.RegisterUserForm.datepicker.value == "") {
            alert("Please select date !");
            document.RegisterUserForm.datepicker.focus();
            return false;
        }
        if (document.RegisterUserForm.Enquiry.value == "") {
            alert("Please Enter your enquiry!");
            document.RegisterUserForm.Enquiry.focus();
            return false;
        }
        if (document.RegisterUserForm.verificationcode.value == "") {
            alert("Please enter the Verificationcode!");
            document.RegisterUserForm.verificationcode.focus();
            return false;
        }
        return (true);
    }    

    </script>   

$(函数(){
$(#datepicker')。datepicker('option','dateFormat','dd-mm-yy');
});
$(“#日期选择器”)。日期选择器({
minDate:0
});
函数submitform(){
if(validateCatach()){
var sData=$(“#RegisterUserForm”).serialize();
警报(“我来这里处理…”);
$.ajax({
类型:“POST”,
url:“thankyou.php”,
数据来源:sData,
//async:false,
成功:功能(数据){
如果(数据=“是成功”){
警报(“您的查询已发送…”);
返回true;
}否则{
警报(“某些错误,请再次键入…”);
返回false;
}
}
});
}
返回false;
}
函数validateCatach(){
if(validateForm()){
var captchaval=$(“#验证代码”).val();
$.ajax({
类型:“POST”,
url:“captchache.php”,
async:false,
数据:{
验证代码:captchaval
},
成功:功能(数据){
如果(数据=“成功”){
警报(“captchacheck success..”;
返回true;
}否则{
警报(“您键入的安全代码错误。请重试。”);
返回false;
}
}
});
}
}
函数validateForm(){
如果(document.RegisterUserForm.Name.value==“”){
警告(“请提供您的姓名!”);
document.RegisterUserForm.Name.focus();
返回false;
}
如果(document.RegisterUserForm.email.value==“”){
var emailID=document.RegisterUserForm.email.value;
atpos=emailID.indexOf(“@”);
dotpos=emailID.lastIndexOf(“.”);
if(atpos<1 | |(dotpos-atpos<2)){
警报(“请输入正确的电子邮件ID”)
document.RegisterUserForm.email.focus();
返回false;
}
}
if((document.RegisterUserForm.phonenumber.value==“”)| | isNaN(document.RegisterUserForm.phonenumber.value)){
提醒(“请输入您的电话号码”);
document.RegisterUserForm.phonenumber.focus();
返回false;
}
如果(document.RegisterUserForm.yourCelebration.value==“”){
提醒(“请进入您的庆祝活动!”);
document.RegisterUserForm.yourCelebration.focus();
返回false;
}
如果(document.RegisterUserForm.datepicker.value==“”){
警报(“请选择日期!”);
document.RegisterUserForm.datepicker.focus();
返回false;
}
if(document.RegisterUserForm.Enquiry.value==“”){
警告(“请输入您的查询!”);
document.RegisterUserForm.Enquiry.focus();
返回false;
}
如果(document.RegisterUserForm.verificationcode.value==“”){
警报(“请输入验证代码!”);
document.RegisterUserForm.verificationcode.focus();
返回false;
}
返回(真);
}    

您没有从
验证密码返回值。
success
事件的返回值不会以处理代码的方式返回给调用函数。所以为了让你得到想要的输出。你一定要我
  .....
  success: function(e) {
      callSecondFunction();
  }
function validateCaptach() {
    if (validateForm()) {
        var captchaval = $("#verificationcode").val();
        var success;
        $.ajax({
            type: "POST",
            url: "captchacheck.php",
            async: false,
            data: {
                verificationcode: captchaval
            },
            success: function (data) {
                if (data == "SUCCESS") {
                    alert("captchacheck success..");
                    success = true;
                } else {
                    alert("The security code you typed was wrong. Please try again.");
                    success = false;
                }
            }
        });
        return success;
    }
}
<script type="text/javascript">
$(function(){
    $('#datepicker').datepicker('option', 'dateFormat', 'dd-mm-yy');            
});

$("#datepicker").datepicker({
    minDate: 0
});

function submitform () {
    /**
     * Pass the second ajax call as a function
     */
    validateCaptcha(function(){
        var sData = $("#RegisterUserForm").serialize();
        alert('i am here to process..');  

        $.ajax({
            type: "POST",
            url: "thankyou.php",
            data: sData,
            //async: false,
            success: function (data) {
                if (data == "YESSUCCESS") {
                    alert("Your Query has been sent..");
                   return true;
                }
                else {
                    alert("some error please type again...");
                    return false; 
                }
            }
        });
    });

    return false;
}

function validateCaptcha (action) {
    if (validateForm()) {
        var captchaval = $("#verificationcode").val();

        $.ajax({
            type: "POST",
            url: "captchacheck.php",
            async: false,
            data: {
                verificationcode: captchaval
            },
            success: function (data) {
                if (data == "SUCCESS") {
                    alert("captchacheck success..");

                    if (typeof action == "function") {
                        action();
                    }

                    return true;
                }
                else {
                    alert("The security code you typed was wrong. Please try again.");
                    return false;
                }
            }
        });
    }
}

function validateForm () {
    if ($("#RegisterUserForm [name=Name]").val() == "") {
        alert("Please provide your name!");
        $("#RegisterUserForm [name=Name]").focus();
        return false;
    }

    if ($("#RegisterUserForm [name=email]").val() == "") {
        var emailID = $("#RegisterUserForm [name=email]").val();
        atpos = emailID.indexOf("@");
        dotpos = emailID.lastIndexOf(".");

        if (atpos < 1 || (dotpos - atpos < 2)) {
            alert("Please enter correct email ID")
            $("#RegisterUserForm [name=email]").focus();

            return false;
        }
    }

    if (($("#RegisterUserForm [name=phonenumber]").val() == "") || isNaN($("#RegisterUserForm [name=phonenumber]").val())) {
        alert("Please enter your phone Number");
        $("#RegisterUserForm [name=phonenumber]").focus();

        return false;
    }

    if ($("#RegisterUserForm [name=yourCelebration]").val() == "") {
        alert("Please enter your Celebration!");
        $("#RegisterUserForm [name=yourCelebration]").focus();

        return false;
    }

    if ($("#RegisterUserForm [name=datepicker]").val() == "") {
        alert("Please select date !");
        $("#RegisterUserForm [name=datepicker]").focus();

        return false;
    }

    if ($("#RegisterUserForm [name=Enquiry]").val() == "") {
        alert("Please Enter your enquiry!");
        $("#RegisterUserForm [name=Enquiry]").focus();

        return false;
    }

    if ($("#RegisterUserForm [name=verificationcode]").val() == "") {
        alert("Please enter the Verificationcode!");
        $("#RegisterUserForm [name=verificationcode]").focus();

        return false;
    }

    return true;
}
</script>