jQuery(document).ready(function(jQuery) {
function checkEmail(email){
jQuery.post('someroute.php',
{email:eamil},
function(data){
if(data==error){
return false;
}
);
return true;
}
jQuery('#myform').submit(function(){
// como code and at the momment this
var result true;
//then I check email
var email = ('#myemail').val();
result = checkEmail(email);
return result;
});
問題是這樣的,一個checkEmail
功能,第一回真正的函數,然後返回值jQuery.post
功能。爲什麼?jQuery的提交表單要求使用Ajax
我檢查並提交,首先返回true,如果你停止提交,那麼你釋放該帖子返回值。發佈工作正常,但我不明白爲什麼功能checkEmail
不會等到發佈後返回值並繼續直到結束返回true。
你的代碼缺少'}'和'})'。如果您正確縮進代碼並傳遞一個快速的jshint,您甚至可以在發佈問題之前就能夠捕獲這些錯誤。 – elclanrs