Created
March 22, 2019 07:50
-
-
Save umkasanki/515012529b76f30054d48c5c02062777 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$('#js-contact-form').submit(function(ev) { | |
// Prevent the form from actually submitting | |
ev.preventDefault(); | |
// Send it to the server | |
$.post({ | |
url: '/', | |
dataType: 'json', | |
data: $(this).serialize(), | |
success: function(response) { | |
if (response.success) { | |
$('#js-form-header').hide(); | |
$('#js-form-thanks').show(); | |
$('input, textarea').val(''); | |
} else { | |
// response.error will be an object containing any validation errors that occurred, indexed by field name | |
// e.g. response.error.fromName => ['From Name is required'] | |
alert('An error occurred. Please try again.'); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment