$(document).ready(function () { $('#btnLogin').click(function (e) { e.preventDefault(); path = $(this).data('path'); $("#btnLogin").prop("disabled", true) $('#btnLogin').html(" Logging in..."); email = $("#email").val(); password = $("#password").val(); $.ajax({ type: "POST", url: '/tenant' + "/login-handler", data: JSON.stringify({ email: email, password: password, }), contentType: "application/json;charset=utf-8", dataType: "json", success: function (result) { $("#btnLogin").prop("disabled", false) $('#btnLogin').html("Login"); if (result.Error) { $("#message").html("
" + result.Message + "
"); //logError(result.Message); //todo } else { if (path == undefined) { path = '/tenant' + '/'; } window.location.href = path; } } }); return false; }); $('input').keypress(function (e) { if (e.which == 13) { $("#btnLogin").click(); return false; //<---- Add this line } }); });