Created
June 5, 2020 16:24
-
-
Save egyjs/0c02b7cff0b22a14b96b0d892bd92f5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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