为什么.submit()没有被调用?

时间:2012-12-02 13:16:59

标签: javascript jquery ajax

这是我的登录表单代码。但是表单提交和JSON响应检索根本没有发生。我哪里错了?

<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>

1 个答案:

答案 0 :(得分:1)

将按钮类型从“按钮”更改为“提交”