I am trying to get a basic AJAX form working. I want to get a line of text to display upon success of a PHP form through AJAX, but on submission of the form I am just directed to the PHP file. Can anyone identify the problem to make the text appear on the same page upon login success?
Code is below:
HTML JS PHP
in order:
$(document).ready(function() {
    $(".loginform").submit(function () {
        var username = $('input[id=username]').val(); 
        var password = $('input[id=password]').val(); 
        $.ajax({
            type: "POST",
            url: "login.php",
            data : "username="+username+"&password="+password,
            type: "POST",
            success: function (data) {
                var success = data['success'];
                if(success == false){
                    var error = data['message'];
                    alert(error);
                }
                if(success == true) {
                    $('#result').write('Login success! Loading dashboard...');                                
                }
            }
        });           
    });
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<p>
Please log in:
<form name="loginform" class="loginform" method="post" action="login.php">
Username: <input name="username" id="username" /><br />
Password: <input name="password" id="password" /><br />
<input name="submit" type="submit" />
</form>
</p>
<p>
<div id="result">
</div>
</p> 
     
     
     
     
    