【发布时间】:2018-04-11 20:20:05
【问题描述】:
Ajax 新手,但是,我不知道哪里出了问题,我认为它是 Javascript。我的 php 页面运行良好,但是,使用此代码,我的登录 Html 只是一遍又一遍地刷新,url 的末尾更改为 ?username=whatIenter&password=whatIenter
JAVASCRIPT
<script type="text/javascript">
$(document).ready(function() {
$('#login_form').submit(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: '/lib/login.php',
data: $(this).serialize(),
success: function(data)
{
alert("WORKED");
}
});
});
});
</script>
HTML
<form id="login_form" action="" method="POST">
<input type="text" id="user" name="username">
<input type="password" id="pass" name="password">
<button id="loginButton" class="login_submit" type="submit" >Login</button>
</form>
【问题讨论】:
-
打开开发者控制台,检查错误。
标签: javascript php jquery html ajax