2011-03-26 2 views
1

특정 버튼을 누르면 전자 메일 주소의 유효성을 검사해야하며 (이 기능은 이미 작동 함) 다음 코드를 가지고 있으며 양식을 게시하려고 시도해야합니다 , "Error"가 다시 발생하면 오류가 표시됩니다. PHP와 JS를 어딘가에 섞어 놓고 있다고 생각합니다.이 jQuery 코드에서 버그를 찾을 수 없음

$('#recoverSub').live('click',function() { 
     $("#recoverPost").validate({ 
      rules: { 
       recoverField: { 
        email: true 
       } 
      }, 
      messages:{ 
       recoverField: { 
        email: "Not a valid email." 
       } 
      } 
     }); 
     if($("#recoverPost").valid()) 
     { 
      $.post('php/recoverPost.php', $('#recoverPost').serialize(), function(){ 
       function(data) { 
        if(data != "Error") 
        { 
         $('#recoverPost').hide(); 
         $('#success').show(); 
        } 
        else 
        { 
         echo "This email is not in our records."; 
        } 
       } 
      }); 
     } 
    }); 
+1

그래서 어떤 부분이 효과가 없습니까? – BrokenGlass

답변

2

$(function() { 
    $('#recoverPost').validate({ 
     rules: { 
      recoverField: { 
       email: true 
      } 
     }, 
     messages: { 
      recoverField: { 
       email: "Not a valid email." 
      } 
     }, 
     submitHandler: function(form) { 
      // the form was valid => post it with AJAX 
      $.post('php/recoverPost.php', $(form).serialize(), function(data) { 
       if(data != 'Error') { 
        $('#recoverPost').hide(); 
        $('#success').show(); 
       } 
       else { 
        alert("This email is not in our records."); 
       } 
      }); 
     } 
    });  
}); 
5
else 
{ 
    echo "This email is not in our records."; 
} 

당신은 아마 echo 대신 alert를 사용하는 의미 :

alert("This email is not in our records."); 
+0

+1 lol 이제 나는 그가 PHP 태그를 사용한 이유를 알고 있습니다. – JCOC611

1
echo "This email is not in our records."; 

당신이 생각하는 것처럼, PHP의 그. 대신를 사용

두 번 기능을 포함했다 $.post
alert("this email is not in our records."; 
1

, 첫 그래서 두 번째는 ...

이 기회를 읽을해야했다 data 전달되지 않습니다

$('#recoverSub').live('click',function() { 
     $("#recoverPost").validate({ 
      rules: { 
       recoverField: { 
        email: true 
       } 
      }, 
      messages:{ 
       recoverField: { 
        email: "Not a valid email." 
       } 
      } 
     }); 
     if($("#recoverPost").valid()) 
     { 
      $.post('php/recoverPost.php', $('#recoverPost').serialize(), function(data){ 
        if(data != "Error") 
        { 
         $('#recoverPost').hide(); 
         $('#success').show(); 
        } 
        else 
        { 
         alert("This email is not in our records."); 
        } 
      }); 
     } 
    }); 
+0

경고 대신 에코 표시 –

관련 문제