JS:
$(document).ready(function() {
$('form').submit(function(event) {
var json;
event.preventDefault();
$.ajax({
type: $(this).attr('method'),
url: $(this).attr('action'),
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(result) {
console.log(result);
return false;
json = jQuery.parseJSON(result);
if (json.url) {
window.location.href = json.url;
} else {
alert(json.status + ' - ' + json.message);
}
},
});
});
});
Html:
<form action="/account/login" method="POST">
<div>
<input name="login" type="text" placeholder="Логин...">
</div>
<div>
<input name="password" type="password" placeholder="Пароль...">
</div>
<div>
<input name="submit" type="submit" value="Войти">
</div>
</form>