验证码验证正在运行,然后邮件发送ajax无效,它既没有显示成功消息也没有显示失败消息。请找到整个代码(因为我无法在此处粘贴代码,因为它给出了一些格式错误)。
http://demo.cateringandevents.in/contactusform.htm
请为此HTML表单建议更好的验证方法。
答案 0 :(得分:0)
尝试实现错误回调选项。这将为您提供必要的错误信息。您现在只实现成功回调,当出现问题时不会调用它。或者,您也可以实现完整的回调,在发送ajax请求后将始终调用该回调。
$.ajax({
type: "POST",
url: "thankyou.php",
data: sData,
success: function () {
// Yeah!
},
error: function(){
// oops
}
});
答案 1 :(得分:0)
下一个功能总是返回false
。你必须以异步的方式思考,当你召唤ajax调用时,程序继续执行,返回false并且一段时间后(每当服务器响应时),成功回调返回true,但是没有人再听它... / p>
function validateCaptach() {
if (validateForm()) {
var captchaval = $("#verificationcode").val();
$.ajax({
type: "POST",
url: "captchacheck.php",
async: false, // Lets make it synchronous
data: {
verificationcode: captchaval
},
success: function (data) {
if (data == "SUCCESS") {
alert("captchacheck sucess..");
return true;
} else {
alert("The security code you typed was wrong. Please try again.");
return false;
}
}
});
}
return false; // No matter what happends it always return false
}
删除最后一个返回并再次使用async: false,
(我已经添加到上一个代码段)它将禁止浏览器停止直到它获得响应然后它将继续正常执行您的程序到成功回调。
如果之前的评论不起作用(async选项似乎在每种情况下都不起作用),您可以尝试将两个函数嵌套在一个中:
function submitform() {
if (validateForm()) {
var captchaval = $("#verificationcode").val();
$.ajax({
type: "POST",
url: "captchacheck.php",
data: {
verificationcode: captchaval
},
success: function (data) {
if (data == "SUCCESS") {
alert("captchacheck sucess..");
sendForm(); // New function
} else
alert("The security code you typed was wrong. Please try again.");
},
error: function(jqXHR, textStatus, errorThrown) { // New error handler
alert("Ouch! something went wrong checking the captcha?. " + errorThrown);
}
});
}
}
function sendForm() {
var sData = $("#RegisterUserForm").serialize();
alert('i am here to process..');
$.ajax({
type: "POST",
url: "thankyou.php",
data: sData,
success: function (data) {
if (data == "YESSUCCESS")
alert("Your Query has been sent..");
else
alert("some error please type again...");
},
error: function(jqXHR, textStatus, errorThrown) { // New error handler
alert("Ouch! something went wrong sending the form?. " + errorThrown);
}
});
}