2012-12-02 230 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

相关问题