I have been working on the final check part for the pset8 exercise. In the registration part, when the username is taken, I could get an alert. However, I couldn't seem to stop it from logging in. I have looked at what's available here and what maybe useful online but couldn't figure it out. I am wondering if I have missed something in the register route instead?
Anyway, my code in the register.html:
<script>
$(document).ready(function() {
$("form").submit(function(event){
$.get("/check", {username: $("#username").val()}, function(data) {
if (data == "false")
{
alert("Username taken");
event.preventDefault();
return false;
}
});
});
});
</script>
<form action="/register" method="post" id="register">
<div class="form-group">
<input autocomplete="off" autofocus class="form-control" name="username" placeholder="Username" type="text" id="username">
</div>
<div class="form-group">
<input class="form-control" name="password" placeholder="Password" type="password">
</div>
<div class="form-group">
<input class="form-control" name="password2" placeholder="Password Confirmation" type="password">
</div>
<button class="btn btn-primary" type="submit" id="button">Register</button>
</form>
Any pointer is hugely appreciated!