我有一個聯繫我們表單與captcha。我提交按鈕點擊我需要執行一個服務器端驗證碼驗證使用第一個AJAX請求,如果成功,然後我打電話給第二個AJAX/Jquery/php發送聯繫我們的郵件。基於第一個AJAX請求調用另一個jQuery/AJAX/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>
'validateCaptach()'沒有'return'語句。從'success'函數返回不會從'validateCaptach'返回。 – Barmar
我也試過這種方式..我們需要分配一個變量,在返回值將被分配和返回..請正確。 – user601140
這不是我在答案中顯示的內容嗎? – Barmar