I am trying to create a login area where when the user clicks login, a Bootstrap modal pops up with the form. What I am trying to do is make it so when the user clicks login, the username and password fields become disabled and a loading image is displayed. If the login is successful, they should be directed to another page. If login fails, an error text will be displayed.
I am not sure how to go about submitting the form in the background and returning wether if the login was successful or not. This is what I have
index.html:
<div class="modal-body">
<form id="loginform" class="form col-md-12 center-block" method="post">
<div class="form-group">
<input type="text" class="form-control input-lg" placeholder="Username">
</div>
<div class="form-group">
<input type="password" class="form-control input-lg" placeholder="Password">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" >Close</button>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
Later on in index.html
<script type="text/javascript">
$(function(){
$('#loginform').on('submit', function(e){
e.preventDefault();
$.post('#',
$('#myForm').serialize(),
function(data, status, xhr){
alert("Oops...");
});
});
});
</script>