重寫表單的checkForm方法,並用if和else解決非同步判斷的問題。 ...
重寫表單的checkForm方法,並用if和else解決非同步判斷的問題。
function checkForm(){
1 var flag = false; 2 3 $.ajaxSetup({async : false}); 4 5 $.post(<?php echo "'".$SITE_PHP.'captchaAjax.php'."'";?>,'captcha='+document.getElementById("captcha").value,function(msg){if(!parseInt(msg)){layer.alert('驗證碼錯誤!',{time:1000});return flag;}else{ 6 7 $.post(<?php echo "'".$SITE_PHP.'loginNamePassAjax.php'."'";?>,'username='+document.getElementById("username").value+'&'+'password='+document.getElementById("password").value,function(msg){if(!parseInt(msg)){layer.alert('用戶名或密碼錯誤!',{time:1000});return flag;}else{ 8 9 flag = true;return flag;}});}}); 10 11 return flag;
}