-1

This chunk of 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);
                        }
                    });
                }
            });

Is making this jQuery

$('a#aLogin').on('click', function (e) {
    e.preventDefault();
    $('.fade_bg').fadeIn(200);
    $('a#aLogin').hide();
});

not work, whether or not I have e.preventDefault() in the AJAX method. How come?

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>
Monica
  • 1,585
  • 3
  • 23
  • 34

1 Answers1

0

You have a syntax error in your first snippet. That's why the second one isn't executed anymore.

Remove the semicolon at the end of this line

if(data == 'You entered an invalid username or password'); <--

All major browser have built-in developer tools. You can find such errors very quick by having a look at the developer console.

In your example chromes console would show you this - http://i43.tinypic.com/xqg48.jpg

Alex B.
  • 947
  • 1
  • 10
  • 19