這是我的登錄表單代碼。但表單提交和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>
當你問你的問題,有這個方便的**如何格式化**框,它的右邊,和預覽在它下面的區域。我希望有一位2k代表的人知道如何格式化可讀的東西。 –
爲什麼id在標題..當你使用類的形式和在jquery提交 –
它沒有被調用,因爲沒有什麼叫它。要提交表單,您需要提交一個提交按鈕。 –