2012-12-02 213 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和id,請 –

+0

是的,你們倆都是對的 – 2012-12-02 15:10:49

相關問題