Javascript 为什么没有调用.submit()?
这是我的登录表单代码。但是表单提交和JSON响应检索根本没有发生。我哪里做错了Javascript 为什么没有调用.submit()?,javascript,jquery,ajax,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">
<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>
用户名或电子邮件
暗语
登录
什么
jQuery(文档).ready(函数(){
jQuery('.login').submit(函数(){
$.ajax({
url:$(this.attr('action'),
类型:$(this.attr('method'),
数据:$(this).serialize(),
成功:功能(响应){
警报(响应);
}
});
返回false;
});
});
将按钮类型从“button”更改为“submit”当您提出问题时,右边有一个方便的“如何格式化”框,下面有一个预览区域。我希望具有>2k代表的人知道如何以易读的方式格式化内容。为什么标题中有id。。当您在jquery中使用类来表示和表示表单时,不会调用submitt,因为并没有调用它的内容。要提交表单,您需要有一个提交按钮。@Puck,请不要混用classess和id