Skip to content

Instantly share code, notes, and snippets.

@egyjs
Created June 5, 2020 16:24
Show Gist options
  • Save egyjs/0c02b7cff0b22a14b96b0d892bd92f5f to your computer and use it in GitHub Desktop.
Save egyjs/0c02b7cff0b22a14b96b0d892bd92f5f to your computer and use it in GitHub Desktop.
$('form').submit(function (event) {
event.preventDefault();
var _this = $(this);
$.ajax({
type: "POST",
url: _this.attr('action'),
data: new FormData(this),
processData: false,
contentType: false,
success: function (data) {
console.log('success');
},
error: function (data) {
if (data.status = 422) {
var i = 0
$('.helper-text').remove();
$('.modal').animate({ scrollTop: 0 }, 'slow');
$.each(data.responseJSON.errors, function (key, value) {
i = i++;
$('[name="' + key + '"]').addClass('invalid error').parent().show();
$('[name="' + key + '"]').after(
"<small class='helper-text text-danger'>" + value +
"</small>")
});
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment