2012-12-02 2 views
-3

이것은 내 로그인 양식 코드입니다. 그러나 양식 제출 및 JSON 응답 검색은 전혀 일어나지 않습니다. 내가 어디로 잘못 가고 있니? 당신이 당신의 질문을했을 때.submit()이 호출되지 않는 이유는 무엇입니까?

<html> 
    <body> 
     <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js"> 
     </script> 
     <div id="login-box"> 
      <form id="login" method="post" class="login" action="http://localhost:3000/login/"> 
       <fieldset class="textbox"> 
        <label class="username"> <span>Username or email</span> 
         <input id="username" name="username" value="" 
         type="text" autocomplete="on" placeholder="Username"> 
        </label> 
        <label class="password"> <span>Password</span> 
         <input id="password" name="password" value="" type="password" 
         placeholder="Password"> 
        </label> 
        <button class="submit button" type="button">Sign in</button> 
        <p> 
         <a class="forgot" href="#">Forgot your password?</a> 
        </p> 
       </fieldset> 
      </form> 
     </div> 
     <button id='theButton'>What?</button> 
     <script> 
      jQuery(document).ready(function() { 
       jQuery('.login').submit(function() { 
        $.ajax({ 
         url: $(this).attr('action'), 
         type: $(this).attr('method'), 
         data: $(this).serialize(), 
         success: function (response) { 
          alert(response); 
         } 
        }); 
        return false; 
       }); 
      }); 
     </script> 
    </body> 
</html> 
+2

"제출"을,이 편리한 ** 그것의 오른쪽에 ** 상자 형식 및 방법 미리보기가 있었다 그것 밑에있는 지역. > 2k 담당자가있는 사람이 물건을 읽을 수 있도록 형식을 지정하는 방법을 알아야합니다. –

+0

제목에 id가 있습니다 .. 양식과 jquery 모두에 클래스를 사용하는 경우 –

+1

부르는 것이 없기 때문에 호출되지 않습니다. 양식을 제출하려면 제출 버튼이 있어야합니다. –

답변

1

변경 "버튼"에서 버튼 유형이

+0

첫 번째 해결 방법은 정확하지만 두 번째 해결 방법은 잘못되었습니다. –

+0

@Puck 및 classess와 ids를 함께 사용하지 마십시오. –

+0

예, 둘 다 맞습니다. –

관련 문제