Last active
December 11, 2015 21:58
-
-
Save GuyHarwood/4666143 to your computer and use it in GitHub Desktop.
post a form using ajax
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 () { | |
$('#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(); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
POSTs a form back to the server using jQuery. Classes are specific to Bootstrap