Created
July 10, 2015 11:06
-
-
Save e-vural/86e99c6749df3568a002 to your computer and use it in GitHub Desktop.
From https://geekalicious.pt/blog/en/javascript/submit-ajax-form-and-custom-validations-with-parsley-js
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
$(document).ready(function() { | |
$("form[name=myForm]").parsley(); | |
$("form[name=myForm]").on('submit', function(e) { | |
var f = $(this); | |
f.parsley().validate(); | |
if (f.parsley().isValid()) { | |
alert('This form is valid'); | |
$.ajax({ | |
url: f.attr('action'), | |
data: f.serialize(), | |
type: 'post', | |
dataType: 'json', | |
success: function(response) { | |
alert('Congrats! Your form was successfully submitted.'); | |
}, | |
error: function() { | |
alert('Crap! There was something wrong.'); | |
} | |
}); | |
} else { | |
alert('This form isn't valid'); | |
} | |
e.preventDefault(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment