unable to send ajax() method and validate user. The login page shoudld hashed the password using md5.js first then pass the hashedPassword through an ajax() method. Any ideas
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main">
<div class="login-box">
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your session</p>
<div id="serverErrorDIV">
<button class="close" type="button" id="serverErrorClose"></button>
<span id="serverErrorMessage"></span>
</div>
<div class="login">
<div class="form-group has-feedback">
<input id="username" class="form-control" placeholder="Username">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input id="password" type="password" class="form-control" placeholder="Password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-4">
<button id="loginBtn" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
jQuery(document).ready(function () {
Login.init();
$('#username').focus();
});
function showErrorMessage(message) {
$('#serverErrorMessage').html(message);
$('#serverErrorDIV').removeAttr('style');
$('#serverErrorDIV').removeClass('display-hide'); }
function login() {
var username = $('#username').val();
var password = $('#password').val();
if (username == "" && password == "") {
showErrorMessage("Kindly enter a valid username & password.");
$('#username').focus();
}
else if (username == "") {
showErrorMessage("Kindly enter a valid username");
$('#username').focus();
}
else if (password == "") {
showErrorMessage("Kindly enter a valid password");
$('#password').focus();
}
else {
$('#loginBtn').attr("disabled", "disabled");
$("#progressIcon").removeClass("hide");
var hashedPassword = md5(password);
** It should be able to send a post request to the controller** $.ajax({ url: '/Account/Login', type: "POST", data: { username: username, //password: password, hashedPassword: hashedPassword, },
$.ajax({
url: '/Account/Login',
type: "POST",
data: {
username: username,
//password: password,
hashedPassword: hashedPassword,
success: function (result) {
if (result == "Failure") {
showErrorMessage("Invalid login attempt.");
$('#loginBtn').removeAttr("disabled");
}
else
window.location.href = result;
},
error: function (jqXHR, textStatus, errorThrown) {
if (textStatus == "Failure") {
showErrorMessage("There is some error while trying to login. Please contact Sales Departmet.");
$('#loginBtn').removeAttr("disabled");
}
else {
window.location.href = result;
}
}
});
}
}
$('#serverErrorClose').on("click", function () {
$('#serverErrorDIV').addClass('display-hide');
$('#password').val("");
});
$('#loginBtn').on("click", function () {
});
</script>
for reducing the code the md5.js and login.js scripts will not show here