这块 AJAX
$('input#adminLogin').on('submit', function() {
var username = $('#username').val();
var password = $('#password').val();
if (username == '' || password == '')
$('#errForm').fadeIn(200).text('You must enter a username and password');
else {
$.ajax ({
type: 'post',
url: '/classes/login/Authenticator.php',
data: $('#login_form').serialize(),
cache: false,
success: function(data) {
if(data == 'You entered an invalid username or password');
$('.actionDiv').fadeIn(200).html(data);
else
$('.fade_bg').fadeOut(200);
}
});
}
});
正在制作这个 jQuery
$('a#aLogin').on('click', function (e) {
e.preventDefault();
$('.fade_bg').fadeIn(200);
$('a#aLogin').hide();
});
不起作用,无论我在 AJAX 方法中是否有 e.preventDefault() 。怎么来的?
HTML
<div class="fade_bg">
<div class="actionDiv">
<span id="errForm"></span>
<form id="login_form" action="./classes/login/Authenticator.php" method="post">
<p>username: <input type="text" name="username" id="username" /></p>
<p>password: <input type="password" name="password" id="password" /></p>
<p><input type="submit" name="adminLogin" value="Log in" id="adminLogin" /></p>
</form>
<p><a id="cancelLogin" href="">Cancel</a></p>
</div>
<div id="topRight">
<a id="aLogin" href="">Admin login</a>
<form id="exit" action="./classes/login/ExitDoor.php" method="post">
<p>
<?php
if ($_SESSION['logged-in'] == 1)
print '<span id="greeting">Welcome, ' . $_SESSION['firstName'] . ' | </span>';
?>
<input id="aLogout" type="submit" name="adminLogout" value="Log out" />
</p>
</form>
</div>