Skip to content

Instantly share code, notes, and snippets.

@GuyHarwood
Last active December 11, 2015 21:58
Show Gist options
  • Save GuyHarwood/4666143 to your computer and use it in GitHub Desktop.
Save GuyHarwood/4666143 to your computer and use it in GitHub Desktop.
post a form using ajax
$(document).ready(function () {
$('#createEvent').click(function () {
$('#feedback').removeClass().html('').fadeOut('slow'); //optional, but nice
var form = $('#createForm');
$.ajax({
type: "POST",
url: $(form).attr('action'),
data: $(form).serialize(),
error: function () {
$('#feedback').addClass('alert alert-error').html('<strong>Error</strong> Something went wrong').fadeIn('slow');
},
success: function () {
$('#feedback').addClass('alert alert-success').text('Created, Add Another?').fadeIn('slow');
$(form)[0].reset();
}
});
});
});
@GuyHarwood
Copy link
Author

POSTs a form back to the server using jQuery. Classes are specific to Bootstrap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment