2013-10-26 5 views
0

안녕하세요 ajax를 사용하여 login.php에 간단한 사용자 이름과 암호를 보내어 false 또는 true 인 2 개의 결과를 반환하려고합니다. 문제는 #login 버튼을 클릭하면 로딩 인 것처럼 보입니다. 그러나 그 이후에는 아무 것도 나타나지 않습니다 (경고 또는 페이지 새로 고침 없음).함수 내에서 Jquery ajax

여기 내 스크립트

<script> 
$(document).ready(function(){ 
    $('#loginbutton').click(function() { 
$('#loginform').submit(function() { // catch the form's submit event 
    $.ajax({ // create an AJAX call... 
     data: $(this).serialize(), // get the form data 
     type: $(this).attr('method'), // GET or POST 
     url: $(this).attr('action'), // the file to call 
     success: function(result) { // on success.. 
      if (result == 'false') { 
      alert("Login failed.\n\nThe username and password doesn't match or perhaps the username doesn't exist.\n\nMake sure you have checked your email and validate your account."); 
      } 
      else if (result == 'true') { 
      alert("Thank you, the registration was successful. \nWe have sent you an email, please validate your account. \nClick OK and we will redirect you to the homepage."); 
      window.location.replace("http://127.0.0.1/wordpress/"); 
     } 
     } 
    }); 
    return false; // cancel original event to prevent form submitting 
});  
}); 
}); 
</script> 

내 로그인 폼의

<?php 
         $templateDirectory= get_bloginfo('template_directory'); 

          echo' 
         <form id="loginform" action="'.$templateDirectory.'/login.php" method="post" class="login"> 
         <a href="#" onClick="document.getElementById(\'loginform\').submit();" class="linkit">LOGIN</a> 
         <div class="para"><input type="text" name="uname" placeholder="Username ..." onkeydown="if (event.keyCode == 13) document.getElementById(\'loginform\').submit()"> <br><input type="password" name="pass" placeholder="Password ..." onkeydown="if (event.keyCode == 13) document.getElementById(\'loginform\').submit()"></div> 
         </form>'; 

?> 

사람이 잘못 :(

답변

1

당신은 무엇을 말해 줄 수 (내가 워드 프레스와 함께이 통합하기 위해 노력하고있어) 클릭 핸들러 내에 폼 제출 핸들러 추가 ... 필요 없음 ... 시도하십시오

$(document).ready(function() { 
    $('#loginform').submit(function() { // catch the form's submit event 
     $.ajax({ // create an AJAX call... 
      data: $(this).serialize(), // get the form data 
      type: $(this).attr('method'), // GET or POST 
      url: $(this).attr('action'), // the file to call 
      success: function (result) { // on success.. 
       if (result == 'false') { 
        alert("Login failed.\n\nThe username and password doesn't match or perhaps the username doesn't exist.\n\nMake sure you have checked your email and validate your account."); 
       } else if (result == 'true') { 
        alert("Thank you, the registration was successful. \nWe have sent you an email, please validate your account. \nClick OK and we will redirect you to the homepage."); 
        window.location.replace("http://127.0.0.1/wordpress/"); 
       } 
      } 
     }); 
     return false; // cancel original event to prevent form submitting 
    }); 
}); 
+0

아니, 그 중 하나를 작동하지 않습니다, 나는 더 많은 물건을 abit 해보고 그것도 false를 호출하는 것 같습니다; 또는 e.preventDefault(); loginform 작동하지 않습니다,하지만 내가 확인했습니다, ID를 잘못 얻지 못했습니다. 무엇이 잘못 되었을까 @ _ @ – Crays

+0

+1'$ (this) .serialize()'에 대해. –