0
我應該將代碼粘貼第一的jQuery的preventDefault不停止執行
$(document).ready(function(){
$("#submit").click(function(e){
$(".error").hide();
var hasError = false;
.... ....
var captcha = $("#captchacode").val();
if(captcha == '') {
$("#captchacode").after('<span class="error">You forgot to enter security image.</span>');
hasError = true;
} else {
$.post("/checkcaptcha.php",
{ captchac: captcha},
function(data){
if (data == "Invalid"){
$("#captchacode").after('<span class="error">Invalid security text. Please try again</span>');
hasError = true;
e.preventDefault();
}
}
);
}
if(hasError == false) {
$(this).hide();
$("#sendEmail li.buttons").append('<img src="images/loading.gif" alt="Loading" id="loading" />');
$.post("/sendemail.php",
{ emailFrom: emailFromVal, name: name, message: messageVal },
function(data){
$("#sendEmail").slideUp("normal", function() {
$("#sendEmail").before('<h1>Success</h1><p>Your email was sent.</p>');
});
}
);
}
return false;
});
});
一切工作。電子郵件正在發送。我在輸入無效驗證碼值時收到錯誤消息。在顯示錯誤消息之後,它將在下一步中完成,表單正在提交。我需要你的建議來解決這個問題。
謝謝。